使用复选框在ASG.NET C#中的Datagrid中检索多个数据项

时间:2011-06-09 07:31:03

标签: c# .net asp.net gridview checkbox

     protected void Button1_Click(object sender, EventArgs e)
  {
   foreach (DataGridItem di in GridView1.Items)
   {
       HtmlInputCheckBox chkBx = (HtmlInputCheckBox)di.FindControl("CheckBox1");
       if (chkBx != null && chkBx.Checked)
       {
          //What should I write to get the Items of that checked row.

       }
     }

   }

帮助我如何检索每个选中行的行项。

我试过这样但是它没有在标签上添加任何东西

      foreach (GridViewRow di in GridView1.Rows)
   {
       HtmlInputCheckBox chkBx = (HtmlInputCheckBox)di.FindControl("CheckBox1");
       if ( chkBx != null && chkBx.Checked)
       {
           FID[j] += di.Cells[2].Text;
           j++;

           Label1.Text += di.Cells[2].Text;

            }

       }

1 个答案:

答案 0 :(得分:2)

它应Rows而不是Items

foreach (GridViewRow di in GridView1.Rows)
{
   HtmlInputCheckBox chkBx = (HtmlInputCheckBox)di.FindControl("CheckBox1");
   if (chkBx != null && chkBx.Checked)
   {
      //What should I write to get the Items of that checked row.

   }
 }