ASP.NET – Gridview RowDeleting事件上没有Datakey!
发布时间:2020-12-16 07:20:59 所属栏目:asp.Net 来源:网络整理
导读:我有一个像这样的GridView: asp:GridView ID="gvwStudents" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" ShowHeader="False" onrowdeleting="gvwStudents_RowDeleting" Columns asp:BoundField DataField="FirstName" / asp:BoundField
我有一个像这样的GridView:
<asp:GridView ID="gvwStudents" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" ShowHeader="False" onrowdeleting="gvwStudents_RowDeleting"> <Columns> <asp:BoundField DataField="FirstName" /> <asp:BoundField DataField="LastName" /> <asp:BoundField DataField="Email" /> <asp:CommandField ShowDeleteButton="True" DeleteText="Remove" /> </Columns> </asp:GridView> 以下是我如何创建GridView绑定的DataTable,以便您知道我正在处理的数据: private DataTable MakeStudentsTable() { DataTable students = new DataTable(); DataColumn ID = students.Columns.Add("ID",typeof(int)); ID.AutoIncrement = true; DataColumn firstName = students.Columns.Add("FirstName",typeof(string)); DataColumn lastName = students.Columns.Add("LastName",typeof(string)); DataColumn email = students.Columns.Add("Email",typeof(string)); return students; } 为什么哦,为什么RowDeleting事件的EventArgs中没有传递密钥?我需要从ADO.NET DataTable中删除当我触发此事件时保持会话状态的记录. 为什么这不起作用? DataKeys只在使用DataSource控件时才有效吗? 解决方法
这有效:
private DataTable MakeStudentsTable() { DataTable students = new DataTable(); DataColumn ID = students.Columns.Add("ID",typeof(string)); DataRow student = students.NewRow(); student["FirstName"] = "foo"; student["LastName"] = "bar"; student["Email"] = "foo@bar.com"; students.Rows.Add(student); return students; } protected void gvwStudents_RowDeleting(object sender,GridViewDeleteEventArgs e) { string id = this.gvwStudents.DataKeys[e.RowIndex].Value.ToString(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – RadGrid在Visual Studio 2013中打开应用程序时,
- asp.net – 如何在Simile时间轴中重新加载数据
- asp.net-mvc – 使用MVC FileStream播放视频文件的问题
- asp.net-web-api – Asp.Net核心WebAPI CORS无效
- asp.net-mvc – EntityType’ApplyantPosition’没有定义键
- asp.net – IIS如何知道它是服务于一个网站还是一个Web应用
- oauth-2.0 – 使用DotNetOpenAuth创建OAuth 2.0服务提供程序
- Asp.net MVC企业级开发(09)---T4模板
- asp.net-mvc-4 – 为什么BeginForm(“Foo”)在查询字符串中
- asp.net-mvc – @ Html.ActionLink如何添加一个查询字符串
推荐文章
站长推荐
热点阅读