C# 如何从asp.net gridview行获取所选行索引
我有一个没有数据键的gridview。单击“行编辑”按钮时,我将使用行编辑方法。我尝试了几种方法来获取行索引,但没有成功C# 如何从asp.net gridview行获取所选行索引,c#,asp.net,webforms,C#,Asp.net,Webforms,我有一个没有数据键的gridview。单击“行编辑”按钮时,我将使用行编辑方法。我尝试了几种方法来获取行索引,但没有成功 protected void gvwCustomerLocation_RowEditing(object sender, GridViewEditEventArgs e) { var index1 = e.NewEditIndex; //gives me an incorrect index number //The Selec
protected void gvwCustomerLocation_RowEditing(object sender, GridViewEditEventArgs e)
{
var index1 = e.NewEditIndex; //gives me an incorrect index number
//The SelectedIndex always equals -1
for (int i = 0; i < gvwCustomerLocation.Rows.Count; i++)
{
if (gvwCustomerLocation.SelectedIndex == 1)
{
}
}
int index = gvwCustomerLocation.EditIndex; //The EditIndex = -1
GridViewRow row = gvwCustomerLocation.SelectedRow; //The SelectedRow = null
var test = row.RowIndex.ToString();
}
受保护的void gvwCustomerLocation\u行编辑(对象发送方,GridViewEditEventArgs e)
{
var index1=e.NewEditIndex;//给了我一个不正确的索引号
//SelectedIndex始终等于-1
对于(int i=0;i
如何获取选定的行索引?我最终放弃了从gridview获取行索引,决定在sql server结果集中创建一个主键,用作前端的键 您应该能够使用和
gvwCustomerLocation.Rows[e.neweditinex]
来获取所选行。@DaveAnderson不幸的是,它没有。当我单击gridview中的第一行时,index1的值是2而不是0。gridview数据绑定的是什么?当您使用gvwCustomerLocation.Rows[e.NewEditIndex]
?@DaveAnderson时,行中的数据绑定到数据集表。您的数据集有多少行?如果e.NewEditIndex=2
它是数据集中的哪一行?您是如何连接事件处理程序的?