Programmatic access to TemplateColumn?

Discussion in 'ASP .Net Datagrid Control' started by matt@mailinator.com, Dec 2, 2005.

  1. Guest

    hello,

    i have a datagrid w/ a TemplateColumn in it, like so:

    <asp:TemplateColumn HeaderText="Select">
    <ItemTemplate>
    <asp:CheckBox ID="chkSelected" Runat="server"/>
    </ItemTemplate>
    </asp:TemplateColumn>

    ....in my c# code-behind, how do i access the checkbox? i need to add a
    javascript onClick attribute.


    thanks!
    matt
     
    , Dec 2, 2005
    #1
    1. Advertising

  2. Guest

    perhaps i should clarify -- i want to access from Page_Load and add the
    javascript Attribute to *all* the row's checkboxes. this way, each row
    of grid has a server-side CheckBox w/ a javascript attribute tagged on.

    tho maybe... i should do this from the grid's ItemDataBound or
    ItemCreated events, and try to use a syntax like the one youve
    provided.


    matt
     
    , Dec 2, 2005
    #2
    1. Advertising

  3. Guest

    this is what i was looking for:

    public void Item_Bound(Object sender, DataGridItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    CheckBox chkSelected = (CheckBox)e.Item.FindControl("chkSelected");
    chkSelected.Attributes.Add("onClick",
    "setCheckboxClickCount(this.checked);");
    }
    }



    matt
     
    , Dec 3, 2005
    #3
    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. =?Utf-8?B?TWlrZU0=?=
    Replies:
    3
    Views:
    874
    Brock Allen
    Mar 18, 2005
  2. Replies:
    6
    Views:
    549
    Brendan Reynolds
    Jun 30, 2005
  3. Replies:
    4
    Views:
    749
  4. =?Utf-8?B?Y2luZHk=?=
    Replies:
    7
    Views:
    2,456
  5. Replies:
    4
    Views:
    415
    Chris
    Aug 18, 2006
Loading...

Share This Page