mercredi 26 avril 2017

asp:GridView unbound template field checkbox clearing

A strange thing is going on here. I had gotten the functionally of my page working the way I wanted it to but had some layout issues that were not what I really wanted. So in trying to fix these issues I found it easier to build a new master page rather than use the default Site.master page. Something, which I had gotten fairly close to finding what was forcing one of my textboxes way more narrow than I wanted it. By building the new master page I alleviated that issue. BUT I introduced a behavioral issue in my code at the same time.

Once I had the page looking the way I wanted it, I found that I had a problem with the asp:GridView on the page. I had created a column in the GridView which was based on an unbound Checkbox feature sitting in a template field.

<asp:TemplateField HeaderText="Tag" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
    <asp:CheckBox runat="server" ID="TagRowChkBx" />
</ItemTemplate>
</asp:TemplateField>

Prior to doing the new custom master page to fix the layout issue, these checkboxes would maintain their checks until they were manually unchecked. After introducing the new master page the 'checks' go away after a selection is used. These checkboxes I read to determine what rows I want to affect a change on in bulk.

I would like to get the functionally back to remaining checked until the user chooses to uncheck them.

Here is the code that causes them to be unchecked in bulk (unintended consequence of the master page change):

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

    // Caputre the checked rows to List
    List<int> EditRows = new List<int>();
    List<string> recordnumber = new List<string>();
    foreach (GridViewRow grv in ActVulListGV.Rows)
    {
        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());
        }
    }

// Place the List in an array 
int[] ERows = EditRows.ToArray();

// Check the DDL values to make sure that the user has made a selection Warn if not.    
     if (ColumnSelectDDL.SelectedValue == "Choose Column To Edit")
    {
        UserMessageLbl.ForeColor = System.Drawing.Color.Red;
        UserMessageLbl.Font.Bold = true;

        UserMessageLbl.Text = " *** You must choose a column to edit! ***";
    mpePopUp.Show();
    }
else
    {
// If Ticket # was selected enable Ticket # Panel
if (ColumnSelectDDL.SelectedValue.ToString() == "TicketNumber")
    {
        EditTicketNumPnl.Visible = true;
        EditTicketClosedPnl.Visible = false;
        EditNotesPnl.Visible = false;
        EditExceptionIDPnl.Visible = false;
        TicketNumFocusTbx.Text = "No Reference Data";
    }
    // If Ticket Closed was selected enable Ticket Closed Panel
    else if (ColumnSelectDDL.SelectedValue.ToString() == "TicketClosed")
    {
        EditTicketNumPnl.Visible = false;
        EditTicketClosedPnl.Visible = true;
        EditNotesPnl.Visible = false;
        EditExceptionIDPnl.Visible = false;
        TicketCldFocusTbx.Text = "";
    }
    // If Notes was selected enable Notes Panel
    else if (ColumnSelectDDL.SelectedValue.ToString() == "Notes")
    {
        EditTicketNumPnl.Visible = false;
        EditTicketClosedPnl.Visible = false;
        EditNotesPnl.Visible = true;
        EditExceptionIDPnl.Visible = false;
        NotesFocusTbx.Text = "No Reference Data";
    }
    // If Exception ID was selected enable Exception ID Panel
    else if(ColumnSelectDDL.SelectedValue.ToString() == "Exception_ID")
    {
        EditTicketNumPnl.Visible = false;
        EditTicketClosedPnl.Visible = false;
        EditNotesPnl.Visible = false;
        EditExceptionIDPnl.Visible = true;
        ExceptionIDFocusTbx.Text = "No Reference Data";
    }
    // format the popup and it's buttons
    EditColMsgLbl.Font.Bold = true;
    SelectedRowsMsgLbl.Font.Bold = true;

    ColEditPnlExt.Show();
    EditColLbl.Text = SelectedColumnItem;

    SelectedRowsLbl.Text = "";
    String divider = "";
    int ticks = 0;

    foreach (string record in recordnumber)
    {
        if (ticks > 0)
            {
                divider = ", ";
                ++ticks;
            }
        else
            {
                ++ticks;
            }
            SelectedRowsLbl.Text += divider.ToString() + record;
        }

    }
}

Thoughts?




Aucun commentaire:

Enregistrer un commentaire