Search code examples
asp.netvb.netgridviewupdatepanel

Gridview is not updating inside of UpdatePanel


I understand that this is a very common issue, I have been reading documentation on it for days, and I am about to pull my hair out over this issue.

BACKGROUND I have multiple Gridviews inside of an UpdatePanel. What is happening, is someone is importing an Excel spreadsheet, I am using OpenXML to shread the data and store it in a VB.NET datatable object. I then run all of that data through a custom validation (based on DB information) and then spit out the exceptions (errors) that occur into a Gridview depending on the exception. the max number is 4 Gridviews in one UpdatePanel (each Gridview has it's own functionality). There are two Gridviews that I am using a button to do an action using the data contained in the Gridview. Those two buttons are also located in the Update Panel, just underneath the corresponding Gridviews. Each Gridview is wrapped in an AJAX Collapsible Panel Extender.

Now, when the user clicks on the button, I have a click event in the code behind where I take the information and depending on the exception that occurred, Update or Insert the DB. I loop through the rows, and if no error occurs, I call the datatable.ImportRow and pass the current row to my "Ready" table. I use a ScriptManager.RegisterStartupScript in order to display an alert box letting them know if any errors occurred. Then, I rebind the exception table and the "Ready" table. I have tried just adding an AsyncPostbackTrigger, I have attempted simply calling udpMain.Update() in the code behind, and tried both options of setting the UpdatePanel's UpdateMode property to "Always" and "Conditional".

HTML

    <asp:UpdatePanel ID="udpMain" runat="server" UpdateMode="Always">
<ContentTemplate>
    <asp:Panel ID="pnlOwnershipDetailsHead" runat="server" Visible="false">
                <div class="windHeader" style="cursor: pointer">
                    <asp:Label id="lblOwnershipDetails" runat="server">Ownership Exceptions</asp:Label>
                    <asp:ImageButton id="btnOwnershipHead" runat="server"/>
                </div>
              </asp:Panel>
               <asp:Panel ID="pnlOwnershipDetailsBody" runat="server" Visible="false" CssClass="pnl">
                <asp:GridView ID="gvOwnershipDetails" runat="server" CssClass="wind" CellPadding="5" AutoGenerateColumns="false">
                    <HeaderStyle CssClass="windHeader" />
                    <Columns>
                        <asp:BoundField DataField="Description" HeaderText="Description" />
                        <asp:BoundField DataField="Serial Number" HeaderText="Serial Number" />
                        <asp:BoundField DataField="Facility" HeaderText="Facility" />
                        <asp:BoundField DataField="Department" HeaderText="Department" />
                        <asp:BoundField DataField="EmpID" HeaderText="EmpID" />
                        <asp:BoundField DataField="Configuration" HeaderText="Config" />
                        <asp:BoundField DataField="Error" HeaderText="Errors" />
                        <asp:TemplateField>
                            <HeaderTemplate> 
                                <asp:CheckBox ID="chkHeader" ToolTip="Select All" runat="server" onclick="changeAllCheckBoxes(this)" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="chkItem" runat="server" ToolTip="Select this item" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                    <asp:Button ID="btnOwnershipDetails" Text="Change Information" runat="server" CssClass="btn editBtn" />
                    <ajax:ConfirmButtonExtender ID="cbeOwnershipDetails" runat="server" TargetControlID="btnOwnershipDetails"
                        ConfirmText="Are you sure you would like to change the ownership information for the selected items?"
                        OnClientCancel="CancelClick"  />
               </asp:Panel>
</ContentTemplate>
    <asp:UpdatePanel>

CODE BEHIND

 Protected Sub btnOwnershipDetails_Click(sender As Object, e As System.EventArgs) Handles btnOwnershipDetails.Click
        Dim importdata As New ImportData
        Dim ownershipdt As Data.DataTable = Session("ownershipdt")
        Dim finalimportdt As Data.DataTable = Session("finalimportdt")
        Dim existsError As Boolean = False

        For Each Row As Data.DataRow In ownershipdt.Rows
            Dim i As Integer = 0
            Dim cb As CheckBox = CType(gvOwnershipDetails.Rows(i).Cells(7).Controls(1), CheckBox)
            If cb.Checked Then
                If importdata.CheckEmpExists(Row("EmpID").ToString) And importdata.CheckSiteExists(Row("Facility").ToString) And importdata.CheckDeptExists(Row("Department").ToString) Then
                    importdata.UpdateDBOwnership(Row("Serial Number").ToString, ClientInfo.GetEmpID(Row("EmpID").ToString), ClientInfo.GetSiteID(Row("Facility").ToString), ClientInfo.GetDeptID(Row("Department").ToString), _
                                                Row("Description").ToString, Row("Configuration").ToString, portalUser.EmployeeText)

                    finalimportdt.ImportRow(Row)
                Else
                    existsError = True
                End If
            End If
            i += 1
        Next
        If existsError = False Then 'Show alert box
            ScriptManager.RegisterStartupScript(udpMain, udpMain.GetType(), "alert", "alert('You have changed the ownership information for the selected rows.')", True)
        Else
            ScriptManager.RegisterStartupScript(udpMain, udpMain.GetType(), "alert", "alert('There was an issue changing ownership to all of the selected rows.')", True)
        End If
        bindGV(gvOwnershipDetails, ownershipdt)
        bindGV(gvImportDetails, finalimportdt)
        'udpMain.Update()
        Session("ownershipdt") = ownershipdt
        Session("finalimportdt") = finalimportdt
        btnEmail.Enabled = True
    End Sub

Solution

  • Finally! I Have found the answer! https://sites.google.com/site/arlen4mysite/full-postback-for-templatef