【问题标题】:Create a Simple One-Record Form With Navigation in .aspx在 .aspx 中使用导航创建一个简单的单记录表单
【发布时间】:2011-12-27 20:08:18
【问题描述】:
在 C# 中,如何创建可以使用表单视图或数据网格视图(或创建新的数据库连接)的新网页?这样我就可以有一个网页,允许用户浏览大约 50 条记录(一次一条记录)。 IE;
我正在使用 Access 文件 (.mdb);如有必要,我愿意转换。
约翰·史密斯
编号:1
电话:440-202-2239
(点击导航)
(下一页)
莎莉·琼斯
编号:2
电话:440-242-2992
(点击导航)
(下一页)
等等
完成此任务的关键字称为“参数化查询”。 *
【问题讨论】:
标签:
asp.net
data-binding
datagrid
webforms
pagination
【解决方案1】:
好吧,我有点生疏了,但我希望以下内容能引导你走上正确的道路。
以下面的标记为例……
<asp:UpdatePanel runat="server" ID="updatePane1">
<ContentTemplate>
<asp:GridView ID="contactGrid" runat="server" EmptyDataText="No Contacts Found" BorderStyle = "Double" AllowSorting = "true" AlternatingRowStyle-BackColor="Beige"
EnableViewState="true" AutoGenerateColumns="False" HeaderStyle-Height = "20" RowStyle-Height = "60" AllowPaging ="true" >
<Columns>
<asp:TemplateField HeaderText="Case Queue" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="Black">
<ItemStyle HorizontalAlign="Center" CssClass = "GridInfo"/>
<ItemTemplate >
<div class="contact">Name:<%# Eval("ContactName") %></div>
<div class="phone">Phone:<%# Eval("PhoneNumber") %></div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Timer ID="Timer1" runat="server" Interval="30000" OnTick="Timer_Tick"> </asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
在你的加载事件中做这样的事情(注意:你需要设置/声明那个“数据”对象):
contactGrid.DataSource = data;
contactGrid.DataBind();
在 PageIndexChanging 事件中执行如下操作:
contactGrid.PageIndex = e.NewPageIndex;