如何获取gridview 选中值的上一行的值?
请高手指教!
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cbox = (CheckBox)row.FindControl("CheckBox1");
if (cbox != null)
{
if (cbox.Checked == true)
{
int id = Int32.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
int uid = id - 1; Label lbl = (Label)GridView1.Rows[row.RowIndex-1].FindControl("Lable2");
Label lab = (Label)row.FindControl("Label1");
string text = lab.Text;
string txt =lbl.Text; (这行总弹出用户代码未处理)
Updatemulu1(id, txt);
Updatemulu(uid, text);
}
}
}
请高手指教!
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cbox = (CheckBox)row.FindControl("CheckBox1");
if (cbox != null)
{
if (cbox.Checked == true)
{
int id = Int32.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
int uid = id - 1; Label lbl = (Label)GridView1.Rows[row.RowIndex-1].FindControl("Lable2");
Label lab = (Label)row.FindControl("Label1");
string text = lab.Text;
string txt =lbl.Text; (这行总弹出用户代码未处理)
Updatemulu1(id, txt);
Updatemulu(uid, text);
}
}
}
Label lbl = (Label)GridView1.Rows[row.RowIndex>0?row.RowIndex-1:row.RowIndex].FindControl("Lable2");
if(lbl!=null)
{}
checkBox cb=(this.GridView1.Rows.FindControl("CheckBox1")) as CheckBox
if(cb.checked==true){
Label lbl = (GridView1.Rows[i].FindControl("Lable2") as Lable).Text;得到ID
}
}下面的就好写了吧
后台 取值 int id =Convert.toint32(GridView1.DataKeys[row.RowIndex].Values["id"]);
根据你取到的Id去数据库里查就OK了