日期:2014-05-18  浏览次数:20489 次

gridview 数据更新的问题 急
主页面   有多个供输入查询条件的TextBox和DropDownList控件   查询记录加载GridView里,无查询时则加载表中所有数据。
分页用的是网上找的自定义分页控件,   用GridView自带编辑操作     点击编辑打开新页面: <asp:HyperLinkField   DataNavigateUrlFields= "CPID "   DataNavigateUrlFormatString= "design_add.aspx?id={0} "     HeaderText= "操作 "   Text= "编辑 "   Target= "_blank "   />
编辑完了保存关闭之后,回到主页面,GridView显示的数据是没有更新
在编辑页面加 <body       onunload= "opener.location.reload() ">   点击保存提示无法刷新。在保存按钮事件里加window.opener.location.href       =       window.opener.location.href;window.close();主页面回到了没有进行查询的情况  
不晓得怎么能实现关闭了编辑页面   主页面gridview能在原来的状态下刷新一下数据

急等高人给予解答和帮助!谢谢


------解决方案--------------------
子页
1. <script type = "text/javascript ">
function aa()
{
window.opener.document.all.imgbtnAdd.fireEvent( 'ondblclick ');
//imgbtnAdd 是个图片,当作保存按钮
}
</script>
2. 子页的 onunload = "aa() "


父页,实现 ICallbackEventHandler 接口,加上以下代码
public string sCallBackFunctionInvocation = string.Empty;
sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "message ", "bb ", "context ");

string ICallbackEventHandler.GetCallbackResult()
{
return " ";
}

void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
//griview 重新绑定代码
}

父页前台:
<img id= "imgbtnAdd " style= " cursor: pointer; " height= "25 " src= "images/button_add.gif " width= "50 " onclick= "openwin() " ondblclick= "doPostBack() " />
//注意其中的事件


脚本:

<script type= "text/javascript ">
function doPostBack()
{
var message = ' ';
  var context = ' ';
<%=sCallBackFunctionInvocation%>
}

function bb(timeMessage, context)
{
    return ;
}


------解决方案--------------------
<asp:HyperLinkField DataNavigateUrlFields= "CPID " DataNavigateUrlFormatString= "design_add.aspx?id={0} " HeaderText= "操作 " Text= "编辑 " Target= "_blank " />

改成

<asp:LinkButton runat= "server " id= "b1 " OnClientClick= ' <%# "return window.showModalDialog( 'design_add.aspx?id= "+ Eval( "CPID ") + " ',null, ' '); "%> ' OnClick= "myDataBind " Text= "编辑 " />

myDataBind 为数据绑定方法
--------------------------------------------


design_add.aspx.cs
--------------------------------------------
protected void ButtonOk_Click(...)
{
// 执行更新操作
Response.Write( " <script> returnValue=true;window.close(); </script> ")
}


------解决方案--------------------
而且你的条件可以用个 viewstate保存,用的时候再取出来