Enabling a control in the Footer Template with a checkbox click

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>
<asp:DropDownList ID="ddlHTCategories" Runat="server"
DataSource="<%# PopulateHTList %>" DataValueField="HeardThroughID"
DataTextField="HeardThrough" Enabled=false></asp:DropDownList>
</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
 
S

satemasov

Ah-ha! The code I have in the ItemCreated needs to be in the
ItemDataBound event! Then it works...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top