打开方式:window.showModalDialog("FrmChooseMenu.aspx",window,"dialogHeight:400px;dialogWidth:300px;center:Yes;Help:No;Resizable:No;Status:Yes;Scroll:auto;Status:no;");
在FrmChooseMenu.aspx屏幕中的dbgrid如下:
<asp:datagrid id="Dg_ChooseMenu" runat="server" AllowPaging="True" BorderStyle="None" CellPadding="1"
BackColor="White" BorderWidth="1px" BorderColor="#93BEE2" AutoGenerateColumns="False" Height="100%"
Width="100%" EnableViewState="False">
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#337FB2"></HeaderStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="选择">
<HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id="RB_Check" onclick="javascript:SelectCheck(this);" runat="server" AutoPostBack="false"
ToolTip="选择列"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="MenuID" HeaderText="编号">
<HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Context" HeaderText="树名称">
<HeaderStyle HorizontalAlign="Center" Width="190px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="[下一页]" BorderWidth="0px" PrevPageText="[上一页]" HorizontalAlign="Right"
ForeColor="#4A3C8C" BackColor="PaleGoldenrod"></PagerStyle>
</asp:datagrid>
获取选中的菜单ID代码如下:
private string GetCheckMenuID()
{
string Return_MenuID="0";
CheckBox Cb_Check = new CheckBox();
for (int Int_i = 0 ; Int_i < this.Dg_ChooseMenu.Items.Count ; Int_i++ )
{
Cb_Check = (CheckBox)this.Dg_ChooseMenu.Items[Int_i].Cells[0].Controls[1];
//Cb_Check = this.Dg_MenuEdit.Items[Int_i].FindControl("RB_Check");
if (Cb_Check.Checked)
{
Return_MenuID=this.Dg_ChooseMenu.Items[Int_i].Cells[1].Text.ToString();
Str_Context=this.Dg_ChooseMenu.Items[Int_i].Cells[2].Text.ToString();
break;
}
}
return Return_MenuID;
}
但我选择的是dbgrid第一页的数据总是正确的,但选择的不是第一页的数据时出来的结果是:
第一页数据(如:我选择第二页或其他页DBGrid的第五条数据时,出来的结果总是:第一页的第五条数据)
但我不用showModalDialog方式打开,却正常的.
在FrmChooseMenu.aspx屏幕中的dbgrid如下:
<asp:datagrid id="Dg_ChooseMenu" runat="server" AllowPaging="True" BorderStyle="None" CellPadding="1"
BackColor="White" BorderWidth="1px" BorderColor="#93BEE2" AutoGenerateColumns="False" Height="100%"
Width="100%" EnableViewState="False">
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#337FB2"></HeaderStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="选择">
<HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id="RB_Check" onclick="javascript:SelectCheck(this);" runat="server" AutoPostBack="false"
ToolTip="选择列"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="MenuID" HeaderText="编号">
<HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Context" HeaderText="树名称">
<HeaderStyle HorizontalAlign="Center" Width="190px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="[下一页]" BorderWidth="0px" PrevPageText="[上一页]" HorizontalAlign="Right"
ForeColor="#4A3C8C" BackColor="PaleGoldenrod"></PagerStyle>
</asp:datagrid>
获取选中的菜单ID代码如下:
private string GetCheckMenuID()
{
string Return_MenuID="0";
CheckBox Cb_Check = new CheckBox();
for (int Int_i = 0 ; Int_i < this.Dg_ChooseMenu.Items.Count ; Int_i++ )
{
Cb_Check = (CheckBox)this.Dg_ChooseMenu.Items[Int_i].Cells[0].Controls[1];
//Cb_Check = this.Dg_MenuEdit.Items[Int_i].FindControl("RB_Check");
if (Cb_Check.Checked)
{
Return_MenuID=this.Dg_ChooseMenu.Items[Int_i].Cells[1].Text.ToString();
Str_Context=this.Dg_ChooseMenu.Items[Int_i].Cells[2].Text.ToString();
break;
}
}
return Return_MenuID;
}
但我选择的是dbgrid第一页的数据总是正确的,但选择的不是第一页的数据时出来的结果是:
第一页数据(如:我选择第二页或其他页DBGrid的第五条数据时,出来的结果总是:第一页的第五条数据)
但我不用showModalDialog方式打开,却正常的.
解决方法:在showModalDialog打开的页面禁用缓存或者在链接尾部加上随机数
方法1:FrmChooseMenu.aspx页面禁用缓存:
在<head></head>之间加<meta http-equiv="pragma"content="no-cache">
方法2:window.showModalDialog("FrmChooseMenu.aspx",window,"dialogHeight:400px;dialogWidth:300px;center:Yes;Help:No;Resizable:No;Status:Yes;Scroll:auto;Status:no;");改造如下:
______________________________________________________________
window.showModalDialog("FrmChooseMenu.aspx"+Math.floor(Math.random()*1000),window,"dialogHeight:400px;dialogWidth:300px;center:Yes;Help:No;Resizable:No;Status:Yes;Scroll:auto;Status:no;");
or:
添加
Response.Buffer=true;
Response.ExpiresAbsolute=System.DateTime.Now.AddSeconds(-1);
Response.Expires=0;
Response.CacheControl="no-cache";
到FrmChooseMenu.aspx页面的Page_Load函数中
or:
添加
Response.Buffer=true;
Response.ExpiresAbsolute=System.DateTime.Now.AddSeconds(-1);
Response.Expires=0;
Response.CacheControl="no-cache";
到FrmChooseMenu.aspx页面的Page_Load函数中这两种方式我都试了,都不行,我想可能不是缓存问题了
-----------------------------------------------
我把后台代码贴出来
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ComFunction;namespace FrameWork.Popedom
{
/// <summary>
/// FrmChooseDict 的摘要说明。
/// </summary>
public class FrmChooseDict : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid Dg_ChooseDict;
protected System.Web.UI.WebControls.Button Btn_OK;
protected System.Web.UI.WebControls.Label Lab_OK;
private FunctionClass FunClass =new FunctionClass();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
string Str_Build="select DictName from Base_DictClass ";
DataBinder(Str_Build);
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Dg_ChooseDict.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.Dg_ChooseDict_PageIndexChanged);
this.Dg_ChooseDict.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.Dg_ChooseDict_ItemDataBound);
this.Btn_OK.Click += new System.EventHandler(this.Btn_OK_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion #region 数据绑定
/// <summary>
/// 数据绑定
/// </summary>
private void DataBinder(string SQLText)
{
Dg_ChooseDict.DataSource = FunClass.SelectToDataSet(SQLText);
Dg_ChooseDict.DataBind();
}
#endregion #region 获取选中的字典类型
private string GetCheckDict()
{
string Return_Dict="";
CheckBox Cb_Check = new CheckBox();
for (int Int_i = 0 ; Int_i < Dg_ChooseDict.Items.Count; Int_i++ )
{
Cb_Check = (CheckBox)Dg_ChooseDict.Items[Int_i].Cells[0].Controls[1];
if (Cb_Check.Checked)
{
Return_Dict=Dg_ChooseDict.Items[Int_i].Cells[1].Text.ToString();
break;
}
}
return Return_Dict;
}
#endregion private void Dg_ChooseDict_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//添加单击
if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.EditItem || e.Item.ItemType==ListItemType.SelectedItem || e.Item.ItemType==ListItemType.AlternatingItem)
{
//添加单击选中事件
e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='E9ECF2'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");
}
} private void Dg_ChooseDict_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
if(Dg_ChooseDict.PageCount>0)
{
Dg_ChooseDict.CurrentPageIndex =e.NewPageIndex;
DataBinder("select DictName from Base_DictClass ");
}
} private void Btn_OK_Click(object sender, System.EventArgs e)
{
string Str_Dict=GetCheckDict();
this.Lab_OK.Text="<script>confirmSelect('" + Str_Dict + "');</script>";
}
}
}
<%@ Page language="c#" Codebehind="FrmChooseDict.aspx.cs" AutoEventWireup="false" Inherits="FrameWork.Popedom.FrmChooseDict" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>选择所属字典类型</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="../ComCss/pubstyle.css" type="text/css" rel="stylesheet">
<base target="_self">
<script language="javascript">
function SelectCheck(chkB)
{
var element;
var i;
if (chkB.checked)
{
element = document.all;
for (i=0;i< element.length;i++)
{
if (element[i].tagName == "INPUT" && element[i].type == "checkbox")
element[i].checked = false ;
}
chkB.checked=true;
}
else
{
chkB.checked=false;
}
}
function confirmSelect(RetStr)
{
window.returnValue = RetStr;
window.close();
}
</script>
</HEAD>
<body leftMargin="0" topMargin="0" MS_POSITIONING="GridLayout">
<form id="FrmChooseDict" method="post" runat="server">
<table cellSpacing="0" cellPadding="0" width="280" border="0">
<tr>
<td colSpan="3" height="30"> <IMG height="15" src="../Image/choose.gif" width="17">
选择所属字典类型</td>
</tr>
<tr>
<td style="HEIGHT: 1px" colSpan="4">
<HR width="100%" SIZE="1">
</td>
</tr>
<tr>
<td colSpan="3">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td vAlign="top">
<asp:datagrid id="Dg_ChooseDict" runat="server" AllowPaging="True" EnableViewState="False" Width="100%"
AutoGenerateColumns="False" BorderColor="#93BEE2" BorderWidth="1px" BackColor="White" CellPadding="1"
BorderStyle="None">
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#337FB2"></HeaderStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="选择">
<HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id="RB_Check" onclick="javascript:SelectCheck(this);" runat="server" AutoPostBack="false"
ToolTip="选择列"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="DictName" HeaderText="字典类型">
<HeaderStyle HorizontalAlign="Center" Width="220px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="[下一页]" BorderWidth="0px" PrevPageText="[上一页]" HorizontalAlign="Right"
ForeColor="#4A3C8C" BackColor="PaleGoldenrod"></PagerStyle>
</asp:datagrid></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" width="175" height="41"><asp:button id="Btn_OK" runat="server" Text="确定" CssClass="ButtonCss"></asp:button></td>
<td width="11"> </td>
<td width="94"><INPUT class="ButtonCss" id="Btn_Cancel" onclick="javascript:window.close()" type="button"
value="取消" name="Btn_Cancel">
<asp:label id="Lab_OK" runat="server"></asp:label></td>
</tr>
</table>
</form>
</body>
</HTML>
function MenuSelect()
{
var RetObj;
//RetObj = window.showModalDialog("FrmChooseDict.aspx?FZ="+Math.floor(Math.random()*1000),window,"dialogHeight:400px;dialogWidth:300px;center:Yes;Help:No;Resizable:No;Status:Yes;Scroll:auto;Status:no;");
RetObj = window.showModalDialog("FrmChooseDict.aspx",window,"dialogHeight:400px;dialogWidth:300px;center:Yes;Help:No;Resizable:No;Status:Yes;Scroll:auto;Status:no;");
if(RetObj==null)
{
return false;
}
else
{
var RetString =RetObj;
document.FrmDictEdit.Tb_DictName.value=RetString;
return true;
}
}
http://community.csdn.net/Expert/topic/4279/4279143.xml?temp=.8691675