asp.net gridview的问题
[size=24px]为什么gridview里面的SelectedIndexChanged编写之后,发现选中行后没有触发事件,调试过了,就是没触发,求问大神,是否需要编写其他代码来支持这个事件,求解!!![/size][b][/b]
[解决办法]
例子
<%@ 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>