lundi 22 mai 2017

Checkbox status clears after review

Picture first to show the interaction with the interface... enter image description here

This is an interface that I am building which enables the editing of one column in the database for multiple rows. This function works perfectly except for the fact that after making the first edit you can't go back and make another edit.

When you choose the Edit Selected button to pop up the panel for the second time. The panel doesn't pop up.

The reason why it doesn't pop up is because in the code below is no longer 'true' even though the checkboxes on the GridView remain checked.

if (((CheckBox)grv.FindControl("TagRowChkBx")).Checked == true)

I haven't been able to figure out why the checked value is no longer true the second pass.

When the user selects the 'Save' on the edit panel it touches off a SP which performs the update of the table.

Here the relevant portion of the GridView definition:

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

Next here is the segment of code that is checking for the boxes to be checked (or not) which is preventing to allow the panel to become visible after the first go around.

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

Hopefully someone might be able to suggest what may be causing this so I can use the function more than once per page display. Thanks, Ken...




Aucun commentaire:

Enregistrer un commentaire