C# GridView 如何取行内容 和 行里面控件内容?

解决方案 »

  1.   

    1.GridView1.Rows[行号].Cells[列号]单元格里面如果没有别的控件 
      textbox.Text = GridView1.Rows[行号].Cells[列号].Text; 2.GridView1.Rows[行号].Cells[列号]单元格里面如果有控件,比如Label则 
      textbox.Text = (GridView1.Rows[行号].Cells[列号].Controls[0] as Label).Text; 关于datagridview的DataGridViewCheckBoxColumn列的问题
         foreach(GridViewRow row in GridView1.Rows) //遍历所有行 
            { 
                if ((row.Cells[10].Controls[0] as CheckBox).Checked) //假定下标为10的列是DataGridViewCheckBoxColumn,判断是否选中 
                { 
                    Response.Write(row.Cells[0].Text); //如果该行是选中的,则打印这行第一个单元格文本