ModalpopupExtender不隐藏,Gridview不刷新
我在 UpdatePanel 中有一个 Gridview,它显示数据库中的一些数据。当您单击编辑按钮时,它会在 ModalPopupextender 中打开一个详细信息视图。当您在此详细视图的文本框中输入数据并单击“更新”时,数据库会更新,但弹出窗口不会隐藏。然后,当我通过单击“关闭”手动关闭它时,除非刷新页面,否则 gridView 不会刷新。我以前能够让它工作,但是在花了一周时间盯着这个问题之后,我决定请你们看看我做错了什么。
这是一些代码! (注意:其中很多都是我发现的教程的改编)
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvReservations" runat="server" CssClass="datagrid" DataKeyNames="dateSubmit"
AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PageSize="10"
DataSourceID="mainTable" Width="95%" OnRowUpdated="gvReservation_RowUpdated" OnRowDataBound="OnRowDataBound" OnSelectedIndexChanged="GvReservations_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="dateSubmit" HeaderText="Date Submitted" SortExpression="dateSubmit"
ReadOnly="true" />
<asp:BoundField DataField="lName" HeaderText="Name" SortExpression="lName" ReadOnly="true" />
<asp:BoundField DataField="startTime" HeaderText="Start Time" SortExpression="startTime"
ReadOnly="true" />
<asp:BoundField DataField="endTime" HeaderText="End Time" SortExpression="endTime"
ReadOnly="true" />
<asp:BoundField DataField="labName" HeaderText="Lab" SortExpression="labName" ReadOnly="true" />
<asp:BoundField DataField="class" HeaderText="Class" SortExpression="class" ReadOnly="true" />
<asp:BoundField DataField="term" HeaderText="Semester" SortExpression="term" ReadOnly="true" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnViewDetails" runat="server" Text="more" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="pnlPopup" runat="server" CssClass="detail" Width="500px" Style="display: none;">
<asp:UpdatePanel ID="updPnlReservationDetail" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
<asp:DetailsView ID="dvReservationDetail" runat="server" DataSourceID="SqlDetail"
OnDataBound="ReservationDetail_DataBound" CssClass="detailgrid" GridLines="None" DefaultMode="Edit" AutoGenerateRows="false"
Visible="false" Width="100%" OnItemUpdating="ReservationDetail_Updating" OnItemUpdated="ReservationDetail_Updated">
<Fields>
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:TextBox ID="tbID" runat="server" Text='<%# Bind("id") %>' ReadOnly="true" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="LabName" DataField="labName" />
<asp:BoundField HeaderText="DateSubmitted" DataField="dateSubmit" />
<asp:TemplateField HeaderText="Start Time">
<EditItemTemplate>
<asp:TextBox ID="startTime" runat="server" Text='<%# Bind("startTime") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="End Time">
<EditItemTemplate>
<asp:TextBox ID="endTime" runat="server" Text='<%# Bind("endTime") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" />
</Fields>
</asp:DetailsView>
<div class="footer">
<asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
这些是我认为会关闭弹出窗口并更新 gridView 的事件
protected void ReservationDetail_Updated(object sender, DetailsViewUpdatedEventArgs e)
{
if (this.Page.IsValid)
{
// move the data back to the data object
// this.dvReservationDetail.UpdateItem(false);
dvReservationDetail.Visible = false;
// hide the modal popup
mdlPopup.Hide();
// refresh the grid
this.gvReservations.DataBind();
this.updatePanel.Update();
}
}
感谢您的帮助!
I have a Gridview within an UpdatePanel that shows some data from my Database. When you click on an edit button, it opens up a detailsView within a ModalPopupextender. When you enter in data in the textBoxes in this detailView and click "update", the Database is updated but the popup does not hide. Then, when I close it manually by clicking "close", the gridView does not refresh unless I refresh the page. I was able to get this to work before, but after spending a week staring at this problem, I decided to ask you guys to see what I am doing wrong.
Here's some code! (Note: a lot of this is an adaptation of a tutorial I found)
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvReservations" runat="server" CssClass="datagrid" DataKeyNames="dateSubmit"
AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PageSize="10"
DataSourceID="mainTable" Width="95%" OnRowUpdated="gvReservation_RowUpdated" OnRowDataBound="OnRowDataBound" OnSelectedIndexChanged="GvReservations_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="dateSubmit" HeaderText="Date Submitted" SortExpression="dateSubmit"
ReadOnly="true" />
<asp:BoundField DataField="lName" HeaderText="Name" SortExpression="lName" ReadOnly="true" />
<asp:BoundField DataField="startTime" HeaderText="Start Time" SortExpression="startTime"
ReadOnly="true" />
<asp:BoundField DataField="endTime" HeaderText="End Time" SortExpression="endTime"
ReadOnly="true" />
<asp:BoundField DataField="labName" HeaderText="Lab" SortExpression="labName" ReadOnly="true" />
<asp:BoundField DataField="class" HeaderText="Class" SortExpression="class" ReadOnly="true" />
<asp:BoundField DataField="term" HeaderText="Semester" SortExpression="term" ReadOnly="true" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnViewDetails" runat="server" Text="more" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="pnlPopup" runat="server" CssClass="detail" Width="500px" Style="display: none;">
<asp:UpdatePanel ID="updPnlReservationDetail" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
<asp:DetailsView ID="dvReservationDetail" runat="server" DataSourceID="SqlDetail"
OnDataBound="ReservationDetail_DataBound" CssClass="detailgrid" GridLines="None" DefaultMode="Edit" AutoGenerateRows="false"
Visible="false" Width="100%" OnItemUpdating="ReservationDetail_Updating" OnItemUpdated="ReservationDetail_Updated">
<Fields>
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:TextBox ID="tbID" runat="server" Text='<%# Bind("id") %>' ReadOnly="true" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="LabName" DataField="labName" />
<asp:BoundField HeaderText="DateSubmitted" DataField="dateSubmit" />
<asp:TemplateField HeaderText="Start Time">
<EditItemTemplate>
<asp:TextBox ID="startTime" runat="server" Text='<%# Bind("startTime") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="End Time">
<EditItemTemplate>
<asp:TextBox ID="endTime" runat="server" Text='<%# Bind("endTime") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" />
</Fields>
</asp:DetailsView>
<div class="footer">
<asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
These are the events where I thought it would close the popup and update the gridView
protected void ReservationDetail_Updated(object sender, DetailsViewUpdatedEventArgs e)
{
if (this.Page.IsValid)
{
// move the data back to the data object
// this.dvReservationDetail.UpdateItem(false);
dvReservationDetail.Visible = false;
// hide the modal popup
mdlPopup.Hide();
// refresh the grid
this.gvReservations.DataBind();
this.updatePanel.Update();
}
}
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在页面上使用单个更新面板
将所有控件放入其中。
try to use single update panel on page
place all controls inside it.