当执行
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
的时候
我想把选中行的某个值赋给一个变量应该怎么操作?
string temp;
temp= gridview1.????? 应该怎么写我的gridview里一共有3列,想分别获得这三个值(选中行的 三个值)

解决方案 »

  1.   

    temp= GridView1.CurrentRow.Cells[0].Value.ToString(),0就是该组件列的索引值,你可以返回你需要列的索引值。
      

  2.   

    想获取这三个值?
                string temp = "";
                for (int i = 0; i <= dataGridView1.CurrentRow.Cells.Count - 1; i++)
                {
                     temp += dataGridView1.CurrentRow.Cells[i].Value.ToString() + ",";
                }
                temp = temp.Substring(0, strlist.Length - 1);
    结果就是 temp = "a,b,c".....
    最后在把每个值取出来,放在数组里面..
      

  3.   

    strlist 改成 temp.........我复制错了......
      

  4.   

    奇怪 我程序里没有 currentrow  但是我找到了selectedrow
    应该是一样的吧
      

  5.   

    老大们,找不到currentrow这项啊 找了半天别的也不好用啊
      

  6.   


                int i=GridView1.SelectedIndex;
                GridView1.Rows[i];
    获取该行数据.
      

  7.   

    这样获得的不是该行的数据啊 是:System.Web.UI.WebControls.GridViewRow 而不是对应的数据啊。我试了GridView1.Rows[i].Cells[1].Text.ToString() 获得的就是空 郁闷啊
      

  8.   

    string a = GridView1.Rows[1].Cells[1].Text;
    我试了可以的,你是不是这行或者这列是控件什么的
    下面这样也可以的
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
            {
                string a = GridView1.SelectedRow.Cells[1].Text;
            }
      

  9.   

    WEB?用模版.然后FindControl