內更新我明白,這是一個很常見的問題,我已經在它閱讀文檔的天,我就要拉我的頭髮,在這個問題上。GridView控件的UpdatePanel不
背景 我有一個UpdatePanel中的多個Gridviews。發生了什麼,有人正在導入Excel電子表格,我正在使用OpenXML將數據分頁並將其存儲在VB.NET數據對象中。然後,我通過自定義驗證運行的所有數據(基於數據庫的信息),然後吐出發生到一個GridView取決於例外的例外(錯誤)。一個UpdatePanel中的最大數量是4個Gridviews(每個Gridview都有它自己的功能)。有兩個Gridviews我正在使用按鈕來使用Gridview中包含的數據執行操作。這兩個按鈕也位於更新面板中,位於相應的Gridviews下方。每個Gridview都包裝在一個AJAX Collapsible Panel Extender中。
現在,當用戶點擊按鈕時,我在代碼後面的代碼中有一個單擊事件,我在這裏獲取信息,並根據發生的異常更新或插入數據庫。我遍歷行,如果沒有錯誤發生,我調用datatable.ImportRow並將當前行傳遞給我的「就緒」表。我使用ScriptManager.RegisterStartupScript來顯示一個警告框,讓他們知道是否發生了任何錯誤。然後,我重新綁定異常表和「就緒」表。我試着只是添加一個AsyncPostbackTrigger,我試圖在後面的代碼中簡單地調用udpMain.Update(),並嘗試將UpdatePanel的UpdateMode屬性設置爲「Always」和「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>
後面的代碼
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
刪除更新面板,看看它的作品,如果不是你得到了什麼錯誤。 – Aristos
沒有錯誤,但它也沒有工作。如果沒有UpdatePanel,爲了Gridview的更新,我必須發送一個完整的回傳正確的? –
保持更新面板關閉你的代碼,直到你發現你真正的問題在這裏 - 標題現在是錯誤的,UpdatePanel不是你的問題 – Aristos