重写render,利用ClientScript,在客户端注册select,回发到服务器,触发服务器端的行选择事件。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //重写render,利用ClientScript,在客户端注册select,回发到服务器,触发服务器端的行选择事件。
2 protected override void Render(HtmlTextWriter writer)
3 {
4 foreach (GridViewRow row in GridView1.Rows)
5 {
6 if (row.RowType == DataControlRowType.DataRow)
7 {
8 row.Attributes["onclick"] = ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true);
9 row.Attributes["style"] = "cursor:pointer";
10 row.Attributes["title"] = "单击选择行";
11 }
12 }
13 base.Render(writer);
14 }
2 protected override void Render(HtmlTextWriter writer)
3 {
4 foreach (GridViewRow row in GridView1.Rows)
5 {
6 if (row.RowType == DataControlRowType.DataRow)
7 {
8 row.Attributes["onclick"] = ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true);
9 row.Attributes["style"] = "cursor:pointer";
10 row.Attributes["title"] = "单击选择行";
11 }
12 }
13 base.Render(writer);
14 }