我有一个没有数据键的gridview。单击行编辑按钮时,将进入行编辑方法。我尝试了几种获取行索引的方法,但是没有运气。
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();
}
如何获取所选的行索引?
答案 0 :(得分:0)
我最终放弃了从gridview获取行索引的决定,决定在sql服务器结果集中创建一个主键,以用作前端的键。