选中复选框,但得到错误 [英] checkbox checked but getting false
本文介绍了选中复选框,但得到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在转发器中有一个复选框,
当用户选中该框时会保存这些值,
但是在代码中,当我把它放在循环中时......复选框值变为false。
Hi guys,
I have a checkbox in a repeater,
when user checked that box it will save those values,
but in the code, when i put this in loop... the checkbox value getting false.
foreach (RepeaterItem item in Repeater1.Items)
{
//TextBox t = (TextBox)item.FindControl("txtrows");
CheckBox chk = (CheckBox)item.FindControl("chkSelect");
if (chk.Checked)//getting false
{
RadioButton rb1 = (RadioButton)item.FindControl("rb15");
RadioButton rb2 = (RadioButton)item.FindControl("rb20");
bool fifteen = rb1.Checked;
bool twenty = rb2.Checked;
HiddenField hdn = (HiddenField)item.FindControl("hdnChemical");
int ChemicalID = Convert.ToInt32(hdn.Value);
TextBox rows = (TextBox)item.FindControl("txtrows");
string sRows = rows.Text;
TextBox vol = (TextBox)item.FindControl("txtvolume");
string svol = vol.Text;
//Insert query here!
string data = PrjID + "," + fifteen + "," + twenty + "," + sRows + "," + svol + "," + Session["UserRecID"].ToString() + "," + ChemicalID.ToString();
i = bl.InsertAssignChemicals(data);
}
}
if (!IsPostBack)
{
int recid = Convert.ToInt32(Request.QueryString["RECID"]);
getProjectDetails(recid);
Fill_Repeater();
}
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table class="table table-bordered table-hover">
<thead class="bg-light-blue">
<tr>
<th>
S.No.
</th>
<th>
Select
</th>
<th>
Main Chemicals
</th>
<th>
15%
</th>
<th>
20%
</th>
<th>
No.of Rows
</th>
<th>
Volume
</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td valign="middle" align="center" style="width: 50px" class="bg-gray">
<%# Container.ItemIndex + 1 %>
</td>
<td align="center" style="width: 50px">
<asp:CheckBox ID="chkSelect" runat="server" />
</td>
<td>
<asp:Label ID="lblchm" CssClass="textBlack" Font-Bold="true" runat="server" Text='<%# Eval("CName") %>'></asp:Label>
<asp:HiddenField ID="hdnChemical" runat="server" Value='<%# Eval("RecID") %>' />
</td>
<td align="center" style="width: 50px">
<asp:RadioButton ID="rb15" GroupName="percentage" runat="server" />
</td>
<td align="center" style="width: 50px">
<asp:RadioButton ID="rb20" GroupName="percentage" runat="server" />
</td>
<td>
<asp:TextBox ID="txtrows" runat="server" CssClass="form-control" AutoPostBack="False"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtrows"
SetFocusOnError="true" ForeColor="Red" ErrorMessage="Please Enter Only Numeric"
Style="z-index: 101; left: 424px; position: absolute; top: 285px" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="txtvolume" runat="server" CssClass="form-control" AutoPostBack="False"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtvolume"
SetFocusOnError="true" ForeColor="Red" ErrorMessage="Please Enter Only Numeric"
Style="z-index: 101; left: 424px; position: absolute; top: 285px" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody> </table>
</FooterTemplate>
</asp:Repeater>
任何人都可以...... plzzz帮助我
谢谢
Can anyone...plzzz help me
thanks
推荐答案
>< / asp:RegularExpressionValidator>
< / td>
< td>
< asp:TextBox ID = txtvolumerunat =serverCssClass =form-controlAutoPostBack =False>< / asp:TextBox>
< asp:RegularExpressionValidator ID =RegularExpressionValidator2runat =serverControlToValidate = txtvolume
SetFocusOnError =trueForeColor =RedErrorMessage =请输入仅数字
Style =z-index:101;左:424px;位置:绝对;顶部:285pxValidationExpression =^ \d +
"></asp:RegularExpressionValidator> </td> <td> <asp:TextBox ID="txtvolume" runat="server" CssClass="form-control" AutoPostBack="False"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtvolume" SetFocusOnError="true" ForeColor="Red" ErrorMessage="Please Enter Only Numeric" Style="z-index: 101; left: 424px; position: absolute; top: 285px" ValidationExpression="^\d+
>< / asp:RegularExpressionValidator>
< / td>
< / tr>
< / ItemTemplate>
< FooterTemplate>
< / tbody>< / table>
< / FooterTemplate>
< / asp:Repeater> ;
"></asp:RegularExpressionValidator> </td> </tr> </ItemTemplate> <FooterTemplate> </tbody> </table> </FooterTemplate> </asp:Repeater>
任何人都可以...... plzzz帮助我
谢谢
Can anyone...plzzz help me
thanks
我不知道关于web
但是我在Windows应用程序中遇到了Datagridview这个问题。
为此我实现了dataGridView1的CurrentCellDirtyStateChanged事件。
希望这可以帮到你:
I don't know about web
But I encountered with this issue in windows application for Datagridview.
For this I have implemented CurrentCellDirtyStateChanged event of dataGridView1.
Hope this may help u:
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
这篇关于选中复选框,但得到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文