[英]How to get the selected row index from an asp.net gridview row
我有一個沒有數據鍵的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();
}
如何獲得選定的行索引?
我最終放棄了從gridview獲取行索引的決定,決定在sql服務器結果集中創建一個主鍵,以用作前端的鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.