Monday, July 20, 2009

open new window in GridView using OnRowCreated

In GridView using "OnRowCreated" function we can add onClick function.

here is the sample code

html code

<asp:TemplateField HeaderText="Header 3">
<asp:Label ID="Label1" runat="server" Text="Click Me"></asp:Label>

and CodeBehind is

protected void Gridview1_RowCreated(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
Label l = (Label)e.Row.FindControl("Label1");
if (l != null)
string script = "'Default.aspx');";
l.Attributes.Add("onclick", script);

run the Application and click "Click Me" it will open new window , indirectly we are adding
OnClick Event in That Row.

No comments:

Post a Comment