I have a user control with a grid view that I wish the user to be able to click the row and cause the selectedIndexChanged event to fire on the grid view. To do this I have overridden the Render method on the user control to do the following:
{
if (GridView1.Rows.Count > 0)
{
foreach (GridViewRow rowin GridView1.Rows)
{
if (row.RowType ==DataControlRowType.DataRow)
{
row.Attributes["onclick"] = Page.ClientScript.GetPostBackEventReference(this.GridView1,"Select$"+ row.RowIndex,true);
row.Style["cursor"] ="hand";
}
}
}
base.Render(writer);
}
protected
overridevoid Render(System.Web.UI.HtmlTextWriter writer){
if (GridView1.Rows.Count > 0)
{
foreach (GridViewRow rowin GridView1.Rows)
{
if (row.RowType ==DataControlRowType.DataRow)
{
row.Attributes["onclick"] = Page.ClientScript.GetPostBackEventReference(this.GridView1,"Select$"+ row.RowIndex,true);
row.Style["cursor"] ="hand";
}
}
}
base.Render(writer);
}
However, If I put a update panel around my grid, this no longer works (the style and onclick attribute are no longer available). The exact same code placed directly on a page will work correctly. I have spent hours looking into this and as I cannot find anything, I can only assume that I am missing something fundamental. I can post a full example if it will help. Cheers