通过checkbox 获取 gridview的某个字段 求.NET 达人
各位达人:
在gridview中 如何通过勾选checkbox 获取改行的第二列字段
其中:checkbox是gridview的模板列
具体看下图程序 gridview checkbox .net
[解决办法]
no..no.. 你应该这么写:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataGridDataBind();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
public void BindData()
{
DataTable dt = new DataTable();
dt.Columns.Add("编号");
dt.Columns.Add("订单号");
dt.Columns.Add("时间");
for (int i = 1; i < 11; i++)
{
DataRow dr = dt.NewRow();
dr["编号"] = i;
dr["订单号"] = 10000+i;
dr["时间"] = DateTime.Now;
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] strArr = new string[GridView1.Rows.Count];
int j = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb = GridView1.Rows[i].FindControl("CheckBox") as CheckBox;
if (cb != null && cb.Checked)
{
strArr[j] = GridView1.Rows[i].Cells[2].Text.ToString();
j++;
}
}
TextBox1.Text = strArr[0];
TextBox2.Text = strArr[1];
TextBox3.Text = strArr[2];
TextBox4.Text = strArr[3];
}