在此输入代码我在CheckBox
模板中有一个GridView
。选中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>
答案 0 :(得分: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;
}
}