Enabling a control in the Footer Template with a checkbox click

Discussion in 'ASP .Net Datagrid Control' started by satemasov@gmail.com, May 31, 2006.

  1. Guest

    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
     
    , May 31, 2006
    #1
    1. Advertising

  2. Guest

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

    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>
    > <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
     
    , May 31, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Assimalyst
    Replies:
    3
    Views:
    1,914
    Assimalyst
    Aug 9, 2005
  2. =?Utf-8?B?V2FxYXMgUGl0YWZp?=

    Enabling Forms Authentication Stops Button Click Events

    =?Utf-8?B?V2FxYXMgUGl0YWZp?=, Aug 21, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    346
    =?Utf-8?B?V2FxYXMgUGl0YWZp?=
    Aug 21, 2005
  3. Henrik
    Replies:
    1
    Views:
    428
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
  4. Waqas Pitafi

    Enabling Forms Authentication Stops Button Click Events

    Waqas Pitafi, Aug 21, 2005, in forum: ASP .Net Security
    Replies:
    3
    Views:
    169
    Waqas Pitafi
    Aug 22, 2005
  5. James Radke

    Problem enabling checkbox from client-side javascript - help!

    James Radke, Jan 22, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    465
    Jeffrey Tan[MSFT]
    Jan 27, 2004
Loading...

Share This Page