我如何在数据列表中使用分页 [英] how can i use paging in my datalist
本文介绍了我如何在数据列表中使用分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
源代码数据列表为
source code datalist is
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:DataList ID="DataList1" runat="server" BackColor="#CCCCCC"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4"
CellSpacing="2" ForeColor="Black" GridLines="Both"
onselectedindexchanged="DataList1_SelectedIndexChanged">
<FooterStyle BackColor="#CCCCCC" />
<ItemStyle BackColor="White" />
<SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<HeaderTemplate>
<tr>
<b>
<th>
emp_id
</th>
<th>
</th>
<th>
emp_add
</th>
<th>
emp_mob
</th>
<th>
salary
</th>
</b>
</tr>
<br />
</HeaderTemplate>
<ItemTemplate>
<tr>
<th>
<%#DataBinder.Eval(Container,"DataItem.emp_id") %>
</th>
<th>
<%#DataBinder.Eval(Container,"DataItem.emp_name") %>
</th>
<th>
<%#DataBinder.Eval(Container,"DataItem.emp_add") %>
</th>
<th>
<%#DataBinder.Eval(Container,"DataItem.emp_mob") %>
</th>
<th>
<%#DataBinder.Eval(Container,"DataItem.salary") %>
</th>
</tr>
<br />
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
employee record is displayed
</td>
</tr>
</FooterTemplate>
</asp:DataList>
</form>
</body>
</html>
并且aspx.cs文件后面的代码是
and code behind aspx.cs file is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Configuration;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=(local);Initial Catalog=dbemployee;Integrated Security=yes");
cmd = new SqlCommand("select *from employee", con);
con.Open();
dr = cmd.ExecuteReader();
DataList1.DataSource = dr;
DataList1.DataBind();
con.Close();
}
}
推荐答案
设置属性Allow Paging为true.并允许页面大小
set the property Allow Paging to true.And allow the Page Size
通过以下链接
http://forums.asp.net/t/1108198.aspx [
Go through below link
http://forums.asp.net/t/1108198.aspx[^]
这篇关于我如何在数据列表中使用分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文