Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Enabling a control in the Footer Template with a checkbox click

Reply
Thread Tools

Enabling a control in the Footer Template with a checkbox click

 
 
satemasov@gmail.com
Guest
Posts: n/a
 
      05-31-2006
Hi -

I have two controls in a column of my footer template - a checkbox and
a dropdownlist.

I'd like the dropdownlist to enable/disable depending on the checked
value of the checkbox.

To accomplish this, I've tried a number of options. None of these have
worked for various reasons. Code for the one that came the closest is
below.

Basically, I add the checkbox and the dropdownlist to the footer
template in the .ascx. Then, I add the javascript for the onlick of
the checkbox during the datagrid's footer ItemCreated event.

Problem? It all seems to work, except that the client id's of the
controls are not correct in the javascript. The IDs are set to be just
chkSubCategory and ddlHTCategories. In reality, they should be
_ctl0_dgHeardThrough__ctl65_chkSubCategory and
_ctl0:dgHeardThrough:_ctl65:ddlHTCategories. How do I get the proper
client ID's for these controls?

I tried looping through the datagrid's items in the datagrid_PreRender
event, but no footer item is found.

Thanks for your help - I'd really like to understand how this works...

Best,
Seraphina

Within the datagrid in the .ascx file:
<FooterTemplate>
<asp:CheckBox ID="chkSubCategory" Runat="server" Checked="False"
Text="Sub category of "></asp:CheckBox>
<aspropDownList ID="ddlHTCategories" Runat="server"
DataSource="<%# PopulateHTList %>" DataValueField="HeardThroughID"
DataTextField="HeardThrough" Enabled=false></aspropDownList>
</FooterTemplate>

Private Sub dgHeardThrough_ItemCreated(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgHeardThrough.ItemCreated

If e.Item.ItemType = ListItemType.Footer Then

Dim script As String = "javascript: if(" & _
e.Item.FindControl("chkSubCategory").ClientID &
".checked){" & _
e.Item.FindControl("ddlHTCategories").ClientID & ".disabled
= true}else{" & _
e.Item.FindControl("ddlHTCategories").ClientID & ".disabled
= false}"

CType(e.Item.FindControl("chkSubCategory"),
CheckBox).Attributes.Add("onclick", script)

End If

End Sub

 
Reply With Quote
 
 
 
 
satemasov@gmail.com
Guest
Posts: n/a
 
      05-31-2006
Ah-ha! The code I have in the ItemCreated needs to be in the
ItemDataBound event! Then it works...

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi -
>
> I have two controls in a column of my footer template - a checkbox and
> a dropdownlist.
>
> I'd like the dropdownlist to enable/disable depending on the checked
> value of the checkbox.
>
> To accomplish this, I've tried a number of options. None of these have
> worked for various reasons. Code for the one that came the closest is
> below.
>
> Basically, I add the checkbox and the dropdownlist to the footer
> template in the .ascx. Then, I add the javascript for the onlick of
> the checkbox during the datagrid's footer ItemCreated event.
>
> Problem? It all seems to work, except that the client id's of the
> controls are not correct in the javascript. The IDs are set to be just
> chkSubCategory and ddlHTCategories. In reality, they should be
> _ctl0_dgHeardThrough__ctl65_chkSubCategory and
> _ctl0:dgHeardThrough:_ctl65:ddlHTCategories. How do I get the proper
> client ID's for these controls?
>
> I tried looping through the datagrid's items in the datagrid_PreRender
> event, but no footer item is found.
>
> Thanks for your help - I'd really like to understand how this works...
>
> Best,
> Seraphina
>
> Within the datagrid in the .ascx file:
> <FooterTemplate>
> <asp:CheckBox ID="chkSubCategory" Runat="server" Checked="False"
> Text="Sub category of "></asp:CheckBox>
> <aspropDownList ID="ddlHTCategories" Runat="server"
> DataSource="<%# PopulateHTList %>" DataValueField="HeardThroughID"
> DataTextField="HeardThrough" Enabled=false></aspropDownList>
> </FooterTemplate>
>
> Private Sub dgHeardThrough_ItemCreated(ByVal sender As Object, ByVal e
> As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
> dgHeardThrough.ItemCreated
>
> If e.Item.ItemType = ListItemType.Footer Then
>
> Dim script As String = "javascript: if(" & _
> e.Item.FindControl("chkSubCategory").ClientID &
> ".checked){" & _
> e.Item.FindControl("ddlHTCategories").ClientID & ".disabled
> = true}else{" & _
> e.Item.FindControl("ddlHTCategories").ClientID & ".disabled
> = false}"
>
> CType(e.Item.FindControl("chkSubCategory"),
> CheckBox).Attributes.Add("onclick", script)
>
> End If
>
> End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
click click click Andy Morrison Computer Support 7 12-20-2007 06:50 AM
Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)? Henrik ASP .Net Datagrid Control 1 07-06-2006 12:23 AM
Enabling/Disabling Form controls with checkbox click. Assimalyst ASP .Net 3 08-09-2005 10:51 AM
access to control in footer template =?Utf-8?B?bWFoc2E=?= ASP .Net 3 07-10-2004 05:25 PM
Problem enabling checkbox from client-side javascript - help! James Radke ASP .Net Web Controls 3 01-27-2004 02:28 AM



Advertisments