Gridview 怎样获取ID对应的值?
比如:数据库 ID NAME TYPE
获取的是对应的NAME值?
要在后台获取!!
可以把ID设置为gridview的主键,RowDataBound事件
if (e.Row.RowType == DataControlRowType.DataRow)
{
int i = e.Row.RowIndex;
string strSN = gdvDPSNInfo.DataKeys[i]["ID"].ToString();
}
RowCommand事件中
Control control = e.CommandSource as Control;
GridViewRow gv = control.Parent.Parent as GridViewRow;
gdvDPSNInfo.SelectedIndex = gv.RowIndex;
string strSN= gdvDPSNInfo.DataKeys[gdvDPSNInfo.SelectedIndex]["SN"].ToString();
string strDPAuthorCode = ((System.Web.UI.WebControls.TableRow)(gv)).Cells[3].Text;
谁知道你怎么绑定数据的?
设置DataKeyNames,在程式中 通过 gv.Datakeys[RowIndex].Values["keyName"] 来获取