A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Friday, February 15, 2008

Accessing a Gridview control from Javascript

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);
}
}

Dotnet-Interviews