日期:2014-05-17 浏览次数:20508 次
<%@ Page Language="C#" EnableViewState="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> System.Data.DataView CreateDataSourceByXianhuiMeng() { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32))); dt.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String))); for (int i = 1; i < 8; i++) { dt.Rows.Add(i, "测试" + i.ToString()); } System.Data.DataView dv = new System.Data.DataView(dt); return dv; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.DataSource = CreateDataSourceByXianhuiMeng(); GridView1.DataBind(); } } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { GridView1.SelectedRow.BackColor = System.Drawing.Color.Red; Response.Write("GridView1_SelectedIndexChanged"); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" DataKeyNames="UserId" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateSelectButton="True"> </asp:GridView> </form> </body> </html>