我的父页面Default.aspx里由函数
function OpenWin(ID) {
var strUrl = "ProductUpdate.aspx?ID=" + ID;
var returnValues1 = window.showModalDialog(strUrl, window, "resizable=no;dialogWidth:750px;dialogHeight:650px;status:no;help:no;");
if (returnValues1 == "ok") {
window.location.href = window.location.href;
}
return false;
}
后台用 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>OpenWin(" + id + ")</script>"); 打开子窗口ProductUpdate.aspx
在子窗口ProductUpdate.aspx后台更新之后
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('更新成功');window.returnValues1=\"ok\";window.close();</script>");
但是父窗口ProductUpdate.aspx没有刷新。请问我该怎么做?
function OpenWin(ID) {
var strUrl = "ProductUpdate.aspx?ID=" + ID;
var returnValues1 = window.showModalDialog(strUrl, window, "resizable=no;dialogWidth:750px;dialogHeight:650px;status:no;help:no;");
if (returnValues1 == "ok") {
window.location.href = window.location.href;
}
return false;
}
后台用 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>OpenWin(" + id + ")</script>"); 打开子窗口ProductUpdate.aspx
在子窗口ProductUpdate.aspx后台更新之后
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('更新成功');window.returnValues1=\"ok\";window.close();</script>");
但是父窗口ProductUpdate.aspx没有刷新。请问我该怎么做?
#region 编辑
protected void btEdit_Click(object sender, EventArgs e)
{
int count = 0; // 计算选择checkbox的个数;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
bool isCheck = ((CheckBox)GridView1.Rows[i].FindControl("Checkbox")).Checked;
if (isCheck)
{
count++;
}
}
if (0 == count)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script>alert('请选择一个项编辑')</script>");
}
else if (count > 1)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('一次只能编辑一个项')</script>");
}
else
{
for (int j = 0; j < GridView1.Rows.Count; j++)
{
CheckBox Cb = (CheckBox)GridView1.Rows[j].FindControl("Checkbox");
if (Cb.Checked)
{
int id = Convert.ToInt32(GridView1.DataKeys[j]["id"].ToString());
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>OpenWin(" + id + ")</script>"); }
}
}
} #endregion
1.父窗体部分(页面)把btEdit_Click的后台代码去掉! function CheckAndOpenWin()
{
var iSelectedCount = 0;
var itemID='';
$('#<%=GridView1.ClientID %>').find('input').each(function(){
if($(this).attr('type')=='checkbox' && $(this).is(':checked'))
{
iSelectedCount++;
itemID=$(this).parent().attr('ItemID');
}
}); if(iSelectedCount==0)
{
alert('请选择一个项编辑');
return false;
} if(iSelectedCount>1)
{
alert('一次只能编辑一个项');
return false;
} var strUrl = "ProductUpdate.aspx?ID=" + itemID;
var returnValues1 = window.showModalDialog(strUrl, window, "resizable=no;dialogWidth:750px;dialogHeight:650px;status:no;help:no;");
if (returnValues1 != null) {
return true;
}
return false;
}<asp:Button ID="btEdit" runat="server" OnClientClick="return CheckAndOpenWin();" />
2.父窗体部分(后台代码)父页面中btEdit按钮不需要有任何的后台代码
绑定GridView的代码放到Page_OnPreRender中去GridView的RowDataBound事件中写入如下代码
if(e.Row.RowType==DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem As DataRowView;//假定你绑定的是DataTable
CheckBox Checkbox = e.Row.FindControl("Checkbox") As CheckBox;
Checkbox.Attributes.Add("ItemID",drv["ID"].ToString());
}3. 子窗体页面
弹出的子窗体的页面部分加一句javascript
window.returnValue=null;4. 子窗体后台代码
子窗体后台代码当保存完毕并关闭时写入的后台代码应当为:
Page.ClientScript.RegisterStartupScript(this.GetType(),"returnValue","window.returnValue='ok';window.close();",true);
我想后台没有能把gridview1的键值id赋给ItemID.
即 Checkbox.Attributes.Add("ItemID",drv["ID"].ToString());
请问怎么将 gridview1 的DataKeys[id].tostring绑定给checkbox,
急,在线等
return true;
}
return false;
里加了
if (returnValues1 != null) {
window.location.href = window.location.href; return true;
}
return false;
也没有刷新
然后开启IE的javascript调试,弹出窗口点击确定后,会弹出提示让你选择调试器的,看看生成的returnValue是多少,或者简单一点,alert(returnValues1);绑定的事件在GridView_RowDataBound事件中,仔细看看我回复的部分
再重新定位一下