2017-02-22 3 views
0

これはgridcheckboxを追加するために使用したコードです。これらの結果は最後になります。既存のチェックボックスのグリッドビューテーブルに新しいチェックボックスの行を追加したいのですが、データベースにその新しいチェックボックスの行を追加したい場合はどうすればいいですか?

if (!IsPostBack) 
{ 
    cmd.CommandType = CommandType.Text; 
    cmd.CommandText = " select menu_id from Menu_IDCODE where Access_Code in ('" + strParam + "')"; 
    cmd.Connection = con; 
    sda.SelectCommand = cmd; 
    sda.Fill(ds); 
    for (int j = 0; j <= ds.Tables[0].Rows.Count - 1; j++) 
    { 
     for (int i = 0; i <= GridView1.Rows.Count - 1; i++) 
     { 
      CheckBox CheckBox1; 
      CheckBox1 = (CheckBox)GridView1.Rows[i].FindControl("chkSelect"); 
      //if (CheckBox1.Checked && String = "strConnString") 
      string showId = (string)GridView1.DataKeys[i].Value.ToString(); 

      if (ds.Tables[0].Rows[j][0].ToString() == showId) 
      { 
       //check box checked and correct string 

       CheckBox1.Checked = true; 
       break; 
      } 

答えて

0

更新日:

gv.Rows[0].Cells[0].Controls.Add(new CheckBox()); 

古いコード:

<asp:GridView id="gv" runat="server"> 
<columns> 
<asp:BoundField DataField="id" HeaderText="ID" /> 
<asp:TemplateField> 
<ItemTemplate> 
<asp:CheckBox id="cb1" runat="server" /> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField> 
<ItemTemplate> 
<asp:CheckBox id="cb2" runat="server" /> 
</ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField> 
<ItemTemplate> 
<asp:CheckBox id="cb3" runat="server" /> 
</ItemTemplate> 
</asp:TemplateField> 
</columns> 
</asp:GridView> 
+0

このway..iは将来の場合database..nowからすべてのデータを表示するGridViewの中で一つだけのチェックボックスを使用しているわけではありません私はそのグリッドビューにチェックボックスの行を追加したい。どのようなコードになります – user31121992

+0

@esha私の答えを更新 – mjb

+0
関連する問題