繁体   English   中英

如何从asp.net gridview行获取选定的行索引

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM