日期:2014-05-19  浏览次数:20435 次

gridview 怎样获取所选记录的关键字?
在删除记录的时候,我需要获取所选记录的关键字,用以前dataGrid的方法行不通,请问怎么解决?

------解决方案--------------------
protected void gvNewsList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{

GridView gv = (GridView)sender;
int id = int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
News news = new News();
news.DeleteNewsByNewsID(id);
BindNewsList();
}

gridview 里加DataKeyNames= "newsid "
------解决方案--------------------
http://www.cnblogs.com/weekzero/archive/2006/05/05/392188.aspx

参考
------解决方案--------------------
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//取得当前行号,并取得当前行的GridViewRow对象
int index = e.NewEditIndex;
GridViewRow gvr = GridView1.Rows[index];
//取得当前行单元格中的数据
string docID = gvr.Cells[0].Text;
......
}
------解决方案--------------------
index = e.NewSelectedIndex;
this.GridView1.Rows[index].Cells[0].Text.ToString
------解决方案--------------------
楼上正解
------解决方案--------------------
单个关键字:
GridView1.DataKeys[nRowIndex].value
多个关键字:
GridView1.DataKeys[nRowIndex].values[i]