2011-06-09 50 views
0
 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. 

     } 
    } 

    } 

幫助我如何檢索每個選中行的行項目。使用複選框來檢索ASP.NET中Datagrid中的多個數據項C#

我想這樣的,但它不是追加什麼標籤

 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; 

      } 

     } 

回答

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. 

    } 
} 
+0

其在HtmlinputCheckBox給錯誤我應該怎麼用有我的asp:複選框類型模板。 – Naresh 2011-06-09 07:39:50

+0

你得到的錯誤是什麼? – 2011-06-09 07:42:33

+0

命名空間或類型HtmlInputCheckBox未找到。 – Naresh 2011-06-09 07:44:03

相關問題