【发布时间】:2021-10-19 00:31:57
【问题描述】:
我有一个父页面,它包含一个gridview 和一个aspx 按钮。当用户单击此按钮时,将弹出一个子页面作为模式。从子页面插入数据后,它应该关闭并刷新父页面。因此,父页面上的 gridview 应该显示插入的数据。但是使用下面的代码gridview并不刷新。
Parent.aspx 页面:
if (!IsPostBack)
{
string sqlquery=""//query here
SqlDataAdapter da = null;
da = new SqlDataAdapter(sqlquery);
DataTable dt = new DataTable();
da.Fill(dt);
dt.AcceptChanges();
gv_dept.DataSource = null;
gv_dept.DataSource = dt;
gv_dept.DataBind();
update_gv.Update();
}
<a href="#" id="toolbar_day2" onclick="create();">
Add New</a>
<div align="center">
<asp:UpdatePanel ID="update_gv" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gv_dept" runat="server" AutoGenerateColumns="False"
GridLines="Both" DataKeyNames="dept_id">
<Columns>
<asp:BoundField DataField="dept_name" HeaderText="Name" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
JS:
function create(start, end, resource) {
createModal().showUrl('Child.aspx');
}
function createModal() {
var modal = new DayPilot.Modal();
modal.closed = function () {
if (this.result && this.result.refresh) {
dp_day.commandCallBack("refresh", { message: this.result.message });
dp_week.commandCallBack("refresh", { message: this.result.message });
dp_month.commandCallBack("refresh", { message: this.result.message });
}
dp_day.clearSelection();
dp_week.clearSelection();
dp_month.clearSelection();
};
return modal;
}
DayPilot.Modal = function() {
// default values
this.autoStretch = true; // height will be increased automatically to avoid scrollbar, until this.maxHeight is reached
this.autoStretchFirstLoadOnly = false;
this.border = "10px solid #008080";
this.corners = 'Rounded';
this.className = null;
this.dragDrop = true;
this.height = 650; // see also autoStretch
this.maxHeight = null; // if not set, it will stretch until the bottom space is equal to this.top
this.opacity = 30;
this.scrollWithPage = true; // modal window will scroll with the page
this.top = 3;
this.useIframe = true; // only for showHtml()
this.width = 880;
this.zIndex = null;
}
Child.aspx 页面:
protected async void ButtonOK_Click(object sender, EventArgs e)
{
//Inserting data here.
Hashtable ht = new Hashtable();
ht["refresh"] = "yes";
ht["message"] = "Created.";
Modal.Close(this, ht);
Page.ClientScript.RegisterStartupScript(this.GetType(), "RefreshParentPage", "<script language='javascript'>RefreshParentPage();</script>");
}
function RefreshParentPage() {
window.location.href="Parent.aspx";
}
在 gridview 绑定上放置断点时,数据表会反映新插入的行。但是gridview并没有刷新它。
【问题讨论】:
-
嗯,我没有看到标记,也没有看到当您单击添加按钮时运行的按钮代码,以及该弹出窗口的工作原理。假设在该弹出窗口中单击按钮 ok 按钮会添加到表中,然后相同的代码绑定 gv 以显示新行。但是,我只是将您的页面加载移动到页面加载(是 postback = false)然后可以调用的例程,然后在将行添加到数据库表后可以调用相同的例程。但是,是的,作为一般规则,您必须重新加载/重新绑定网格才能显示新行。
-
@AlbertD.Kallal 抱歉没听懂你说的内容
-
我的意思是你没有显示你的按钮代码,以及你如何弹出那个对话框——所以我们只能猜测这里发生了什么。