On 28 ìÉÓ, 06:59, marksommervi...@yahoo.com wrote:
I have a few questions regarding accessing a gridview control from
Javascript which I would really appreciate some help with.
1. The gridview contains a column of checkboxes as a template field. I
have onclick Javascript on the checkbox but can't figure out how to
determine the row number of the checkbox that was clicked.
2. How do I access a control within the gridview's pagertemplate? The
pagertemplate contains a 1 row table with a button in it that I need
to enable/disable.
Thanks.
Regarding for your first question: you can attach client-side script
within RowDataBound event handler:
<asp:GridView id="GridView1"
OnRowDataBound="GridView1_RowDataBound" ...
<Columns>
<asp:templateField>
<itemtemplate><sp:CheckBox id="CheckBox1" runat="server"></
itemtemplate>
</asp:templateField>
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox CheckBox1 = (CheckBox)e.Row.FindControl("CheckBox1");
CheckBox1.Attributes["onclick"] = string.Format("alert({0});",
e.Row.RowIndex);
}
}
Regards,
Mykola
http://marss.co.ua