Groups | Blog | Home
all groups > asp.net datagrid control > december 2005 >

asp.net datagrid control : Programmatic access to TemplateColumn?


matt NO[at]SPAM mailinator.com
12/1/2005 4:12:01 PM
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
matt NO[at]SPAM mailinator.com
12/2/2005 11:48:17 AM
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
matt NO[at]SPAM mailinator.com
12/2/2005 4:39:17 PM
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
Guogang Hu
1/26/2006 9:43:34 PM
In this blog, it shows you how to create "Select All" check boxes in
datagrid (I guess you are trying to do the same thing here.)
It attaches "onClick" event to the checkboxed in a datagrid using mostly
client side Javascript.
http://huguogang.blogspot.com/2005_12_01_huguogang_archive.html

HTH

[quoted text, click to view]

AddThis Social Bookmark Button