2

在此处输入代码我有一个CheckBox内部GridView模板。检查a 时CheckBox,它应该将列值发送到存储过程,并在另一个 中显示所需的结果gridview。当检查两个复选框时,应在另一个GridView中显示两个列的值。

我的问题是单击第二个复选框会删除第一个复选框的值,并且仅导致第二个复选框的值显示在另一个网格视图中。

 protected void ChkRule_CheckedChanged(object sender, EventArgs e)
    {
        StringCollection sc = new StringCollection();

        for (int i = 0; i < gdYojnaDtl.Rows.Count; i++)
        {

            string yojnaNo = "";
            CheckBox chl = (CheckBox)gdYojnaDtl.Rows[i].Cells[0].FindControl("CheckBox1");
            //CheckBox chl = (CheckBox)sender;
            if (chl != null)
            {
                if (chl.Checked == true)
                {




                    int rowsNo = (Convert.ToInt16(chl.ToolTip) - 1); 
                    yojnaNo = ((Label)gdYojnaDtl.Rows[rowsNo].FindControl("lblYojnaNo")).Text;
                    sc.Add(yojnaNo);


                }

            }
        }

    foreach (string obj in sc)
    {

        objyojnadetail4.YojnaNo = obj;
        DataTable city = objyojnadetail4.Selectcity();
        gdCityDetail.DataSource = city;



        gdCityDetail.DataBind();

    }

}





 <Columns>
                        <asp:TemplateField HeaderText="Scheme Code">
                        <ItemTemplate>
                            <asp:Label ID="lblYojnaNo" runat="server" Text='<%#Eval("Yojna_No")%>' />

                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Scheme Name">
                         <ItemTemplate>
                     <asp:Label ID="lblYojnaName" runat="server" Text='<%#Eval("Yojna_Name")%>' />

                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Assistant Name">
                         <ItemTemplate>
                         <asp:Label ID="lblAsstName" runat="server" Text=' <%#Eval("Asst_Name")%>' />

                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Select for City">
                        <ItemTemplate>
                 <asp:CheckBox ID="CheckBox1"  runat="server"    AutoPostBack="true" 
                  oncheckedchanged="ChkRule_CheckedChanged" 
                  ToolTip="<%#Container.DataItemIndex+1 %> "   CommandName="cbCity"/>





                        </ItemTemplate>
                        </asp:TemplateField>

                    </Columns>
4

1 回答 1

0
//**This code is tested and working fine** 
//at aspx page
<columns>
<asp:TemplateField HeaderText="Checkboxes">
        <ItemTemplate>
          <asp:CheckBox ID="cheker" runat="server" />
        </ItemTemplate>
</asp:TemplateField>
</Columns>

//this button is outside gridview but in same page
<asp:Button ID="check" runat="server" CssClass="btnstyle" Text="Check"       OnClick="btnredirect_Click" />

//代码隐藏中点击事件的方法

protected void btnredirect_Click(object sender, EventArgs e)
{
    Button btn = sender as Button;
    switch (btn.ID)
    {
        case "check":
            {
                for(int i=0;i<Gvshowcart.Rows.Count; i++)
                {
                    CheckBox chl =     (CheckBox)Gvshowcart.Rows[i].Cells[0].FindControl("cheker");
                    if (chl != null)
                    {
                        if (chl.Checked == true)
                        {
                            chl.Checked = false;
                        }
                        else
                        {
                            chl.Checked = true;
                        }
                    }

                }

            }
            break;
    }

}

于 2013-01-09T07:09:00.150 回答