S
satemasov
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
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