Programmatic access to TemplateColumn?

M

matt

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
 
M

matt

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
 
M

matt

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
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top