日期:2014-05-18  浏览次数:20432 次

如何提取GridView第一行的DataKeyNames属性值--在线等
如题

------解决方案--------------------
protected void But_Click(object sender, EventArgs e)
{
//最后,需要对选中项进行操作之前,不能忘了还要最后一次收集当前页的选中情况

for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb = this.GridView1.Rows[i].FindControl( "CheckBox1 ") as CheckBox;
if (cb.Checked)
{
string sid = ((Label)GridView1.Rows[i].Cells[1].FindControl( "Label1 ")).Text;
string cid = GridView1.Rows[i].Cells[6].Text;
string grade = ((DropDownList)GridView1.Rows[i].Cells[10].FindControl( "ddlCatagory ")).Text;
if (grade == "请选择级别 ")
{
Response.Write( " <script language= 'javascript '> alert( '请选择级别! '); </script> ");
}
else
{
teacher tea = new teacher();
tea.set_socre(sid, cid, grade);
Response.Write( " <script language= 'javascript '> alert( '批改成功! '); </script> ");
show_lib_report();
}
}
}
}

看看中间取列表值的代码,问题应当能够解决.
------解决方案--------------------
GridView.DataKeys[0].values
------解决方案--------------------
string s = GridView.DataKeys[0].Value.ToString();
------解决方案--------------------
同意4楼的
------解决方案--------------------
string s = GridView.DataKeys[0].Value.ToString();
同意
------解决方案--------------------
GridView.SelectIndex=0 string values=GridView.DataKeys[0].Value.ToString()