简体   繁体   English

我想在现有的复选框gridview表中添加新的复选框行,也想在数据库中添加该新的复选框行

[英]I want to add new checkbox rows in existing checkbox gridview table and also want to add that new checkbox row in database how will i do it

This is my code i used to add the checkbox in the grid control.also inned to add these result at end. 这是我用来在grid控件中添加checkbox的代码,也可以在最后添加这些结果。

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;
            }

Updated: 更新:

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

old code: 旧代码:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM