C# 检查后清除复选框状态

C# 检查后清除复选框状态,c#,asp.net,gridview,checkbox,C#,Asp.net,Gridview,Checkbox,图片首先显示与界面的交互。。。 这是我正在构建的一个界面,它支持对数据库中的一列进行多行编辑。这个函数工作得很好,除了在进行第一次编辑后不能返回进行另一次编辑 当您选择“编辑选定对象”按钮以第二次弹出面板时。面板没有弹出 它不会弹出的原因是,在下面的代码中,即使GridView上的复选框保持选中状态,也不再是“true” if (((CheckBox)grv.FindControl("TagRowChkBx")).Checked == true) 我一直无法理解为什么第二遍检查的值不再为真

图片首先显示与界面的交互。。。

这是我正在构建的一个界面,它支持对数据库中的一列进行多行编辑。这个函数工作得很好,除了在进行第一次编辑后不能返回进行另一次编辑

当您选择“编辑选定对象”按钮以第二次弹出面板时。面板没有弹出

它不会弹出的原因是,在下面的代码中,即使GridView上的复选框保持选中状态,也不再是“true”

if (((CheckBox)grv.FindControl("TagRowChkBx")).Checked == true)
我一直无法理解为什么第二遍检查的值不再为真

当用户在编辑面板上选择“保存”时,将触发一个SP,该SP执行表格更新

此处是GridView定义的相关部分:

<asp:GridView ID="ActVulListGV" runat="server" OnSelectedIndexChanged="ActVulListGV_SelectedIndexChanged" PageSize="25" AlternatingRowStyle-BackColor="#ccffff" PagerSettings-PageButtonCount="25" Width="100%" AutoGenerateColumns="False" DataKeyNames="RecID" AllowPaging="True" AllowSorting="True" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-BackColor="#99CCFF" HeaderStyle-ForeColor="Black" DataSourceID="Vul_DS">
<Columns>
    <asp:CommandField ShowEditButton="True" ShowSelectButton="True" SelectText="Details" EditText="Edit Row"></asp:CommandField>
    <asp:TemplateField HeaderText="Tag" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
            <asp:CheckBox runat="server" ID="TagRowChkBx" />
        </ItemTemplate>
        </asp:TemplateField>
        <%-- 13 addtional BoundFields -->
</Columns>
</asp:GridView>

听起来像是UpdatePanel/Postback问题..此时不检查回发,因为这是由单击“编辑所选内容”按钮触发的。我看不出回发状态对复选框的状态有什么影响。如果有人知道忽略回发状态的命令语法,我非常愿意尝试一下。我不知道。也许你应该读一下什么控件触发了回发,嗯..?@MethodMan如果这是你的参考,我不会使用“UpdatePanel”(在Ajax扩展中)。我使用的是标准asp:Panel’s.更新的问题和附加评论2017年5月23日美国中部2:20。
protected void EditSelctedBtn_Click(object sender, EventArgs e)
{
  //Read the column select drop down List into Local Varriables 
  String SelectedColumnItem = ColumnSelectDDL.SelectedItem.ToString();
  String SelectedColumnValue = ColumnSelectDDL.SelectedValue.ToString();

  List<int> EditRows = new List<int>();
  List<string> recordnumber = new List<string>();
  int rcounter = 0;
  foreach (GridViewRow grv in ActVulListGV.Rows)
    {
  // Here is where 'true' becomes not true on second pass
      if (((CheckBox)grv.FindControl("TagRowChkBx")).Checked == true)  
    {
   rcounter++;

   //get current row rowindex if  checkbox  in it is checked 
   EditRows.Add(grv.RowIndex);
   //get the record number (RecID)
   recordnumber.Add(grv.Cells[2].Text.ToString());
 }
if (((CheckBox)grv.FindControl("TagRowChkBx")).Checked == true)
{
    //get current row rowindex if  checkbox  in it is checked 
    EditRows.Add(grv.RowIndex);
    //get the record number (RecID)
    recordnumber.Add(grv.Cells[2].Text.ToString());
    }
}
else if (((CheckBox)grv.FindControl("TagRowChkBx")).Checked == false)
{
    UserMessageLbl.Text = "CheckBox value = false!!!";
    PopUpPnl.Visible = true;
    }
else
    {
    UserMessageLbl.Text = "CheckBox value neither true or false = "+ (((CheckBox)grv.FindControl("TagRowChkBx")).ToString());
    PopUpPnl.Visible = true;
    }