① 页面放置 GirdView 控件 用来展示信息列表
页面截图: (操作列中的 "回复" 是个 超链接..点击之后打开模式窗口.并且传值过去)
![](../../UploadFiles/Dezai20100627124813.jpg)
页面源代码
1 <asp:GridView ID="gvnotReturn" runat="server" AutoGenerateColumns="False" AllowPaging="True"
2 BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
3 CellPadding="3" GridLines="Vertical" OnPageIndexChanging="gvnotReturn_PageIndexChanging1"
4 PageSize="5" Width="100%">
5 <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
6 <Columns>
7 <asp:TemplateField HeaderText="选择">
8 <ItemTemplate>
9 <asp:CheckBox ID="cbno" runat="server" />
10 </ItemTemplate>
11 <ItemStyle Width="30px" />
12 </asp:TemplateField>
13 <asp:TemplateField HeaderText="编号">
14 <ItemTemplate>
15 <asp:Label ID="lblId" runat="server" Text='<%# Eval("gid") %>'></asp:Label>
16 </ItemTemplate>
17 <ItemStyle Width="40px" HorizontalAlign="Center" />
18 </asp:TemplateField>
19 <asp:TemplateField HeaderText="标题">
20 <ItemTemplate>
21 <asp:Label ID="Label1" runat="server" Text='<%# Eval("gTitle") %>'></asp:Label>
22 </ItemTemplate>
23 </asp:TemplateField>
24 <asp:TemplateField HeaderText="留言日期">
25 <ItemTemplate>
26 <asp:Label ID="Label2" runat="server" Text='<%# Eval("gPubDate") %>'></asp:Label>
27 </ItemTemplate>
28 <ItemStyle Width="120px" HorizontalAlign="Center" />
29 </asp:TemplateField>
30 <asp:TemplateField HeaderText="操作">
31 <ItemTemplate>
32 <a href="javascript:showModalDialog('ansmsg.aspx?id=<%#Eval("gid")%>');window.location.reload()">
33 回复</a>
34 </ItemTemplate>
35 <ItemStyle Width="50px" HorizontalAlign="Center" />
36 </asp:TemplateField>
37 </Columns>
38 <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
39 <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
40 <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
41 <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
42 <AlternatingRowStyle BackColor="#DCDCDC" />
43 </asp:GridView>
源代码解释:
<a href="javascript:showModalDialog('ansmsg.aspx?id=<%#Eval("gid")%>');window.location.reload()">
回复</a>
很普通的一个页面指向链接.. 传参数ID 过去... 后便添加了 window.location.reload()
这个 window.location.reload() 的意思是 .. 模式窗体关闭之后刷新父页面
ansmsg.aspx 就是要弹出来的 模式窗体咯..
在 ansmsg.aspx 页面添加如下代码:
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = 0; }
这个意思是 禁止 模式窗体页面缓存..
如果不这样做的话... 地址栏ID不变.. 内容也不会变..
就比如..我的功能是这样的.. 如图:
![](../../UploadFiles/Dezai20100627124906.jpg)
这样的情况下..如果不添加禁止页面缓存..我需要回复 留言版信息.. 重新从 "回复" 链接打开的模式窗体..内容是不会变的.. 即使数据库中已经更新了...
如果这个页面紧紧是展示信息..而没有提交按钮...我想这样做已经OK 了...
但是我这个模式窗体有个 提交按钮..意思就是说我需要回发数据回去..
这个时候就出现一个问题....
当点击了 提交按钮之后... 这个模式窗体 会在新页面打开...
失去了模式窗体的意义...
这个不太好...但是怎么解决呢?
方法很简单..
在 作为模式窗体弹出的 那个页面 页面源代码中添加如下代码..
在 作为模式窗体弹出的 那个页面 页面源代码中添加如下代码..
</head>
<base target="_self" />
<body>
本文作者:Donkey 来源: http://www.cnblogs.com/Donkey/archive/2010/06/24/1764296.html
CIO之家 www.ciozj.com 微信公众号:imciow