【发布时间】:2009-09-18 23:06:03
【问题描述】:
我在GridView 中创建了另一个名为删除的列。单击删除时,该行应该被删除,换句话说,我需要获取当前行的用户名才能将其删除。
- 我应该使用哪个事件? (RowDeleting、Rowdeleted 等...)
- 如何从当前行获取用户名?
【问题讨论】:
我在GridView 中创建了另一个名为删除的列。单击删除时,该行应该被删除,换句话说,我需要获取当前行的用户名才能将其删除。
【问题讨论】:
这是一篇关于 typical usages of DataGrid 的精彩文章。
享受吧。
【讨论】:
您可以使用RowDeleting 事件,通过将用户名存储在数据密钥集合中,您可以通过编程方式访问它。
<asp:GridView DataKeyNames="UserName" ID="GridView1"
runat="server" OnRowDeleting="GridView1_RowDeleting">
然后,在后面的代码中使用数据键删除记录。
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string userName = (string) GridView1.DataKeys[e.RowIndex].Value;
DeleteUser(userName);
}
【讨论】:
DataGrid 控件仅使用硬编码列名的示例。我的数据根据用户输入在后台填充,调用 10 个不同的存储过程之一,以显示不同的摘要 - 因此,不同的列名。
1:-
protected void grdLst_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int i = Convert.ToInt32(grdLst.DataKeys[e.RowIndex].Value);
ob.DeleteCoverage(i);
Response.Redirect("fullcoverage.aspx");
}
2:-
GridViewRow row = (GridViewRow)grdlist.Rows[e.RowIndex];
string name = row.Cells[1].Text;
Response.Write(name.Trim());
【讨论】:
tablename.Rows.RemoveAt(datagrid1.currentcell.rowindex);
【讨论】:
columnIndexOfUsername 并使用 GridViewDeleteEvent(请参阅 Phaedrus 的帖子),您应该能够使用以下内容提取 username:@987654324 @