RowEditing的商店ID而不是索引 [英] Store ID of RowEditing Instead of Index

查看:116
本文介绍了RowEditing的商店ID而不是索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的申请,我给用户搜索数据库的选项。当他们点击编辑,我想在GridView只显示他们是由存储其ID更新该行。

In my application, I give the user the option to search the database. When they click edit, I want the GridView to only show the row they are updating by storing its ID.

我想下面的code,但它没有返回比对照其他任何东西。

I'm trying the following code, but it is not returning anything other than the Control.

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
     string value = GridView1.Rows[e.NewEditIndex].Cells[3].ToString();
}

有关如何存储我要找的?值任何想法

Any ideas on how to store the value that I'm looking for?

推荐答案

使用单元格的Text属性。

Use the cell's Text property

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
     string value = GridView1.Rows[e.NewEditIndex].Cells[3].Text;

     // or 
     string value = GridView1.Rows[e.NewEditIndex].Cells[3].Value;
}

或者如果你有声明的控制,<模板列> 为您正在试图获得的值,然后尝试

Or If you have declared the control as <TemplateField> for which you are trying to get the value for then try

string value = ""
Label lblID = (Label)GridView1.Rows[e.NewEditIndex].FindControl("lblID");
value = lblID.Text;

另一种方法是添加的DataKeyNames =ID,而您可以检索使用GridView控件

Another alternative would be to add DataKeyNames="ID" for the gridview which you can retrieve using

 // assuming that the value of your datakey is numeric value 
 long Id = long.Parse(GridView1.DataKeys[e.NewEditIndex].Values["ID"].ToString());   

请注意,您可以到的DataKeyNames 属性添加多个逗号分隔值。

Note you can add multiple comma separated values to DataKeyNames property.

这篇关于RowEditing的商店ID而不是索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆