datalist 分页 datalist 不带分页功能的。你要自己找其他控件来帮助分页。AspNetPager 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HTML:------------------------------------------------------------------<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><body> <form id="form1" runat="server"> <div> <asp:DataList ID="DataList1" runat="server" Style="position: relative" RepeatDirection="Horizontal" CellPadding="4" ForeColor="#333333" OnItemDataBound="DataList1_ItemDataBound"> <ItemTemplate> <table style="width: 100px; position: relative"> <tr> <td> <asp:Label ID="lblauid" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_id") %>'></asp:Label></td> </tr> <tr> <td> <asp:Label ID="lblaufname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_fname") %>'></asp:Label></td> </tr> <tr> <td> <asp:Label ID="lblaucity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"city") %>'></asp:Label></td> </tr> <tr> <td> <asp:Label ID="lblauzip" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"zip") %>'></asp:Label></td> </tr> </table> </ItemTemplate> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <AlternatingItemStyle BackColor="White" /> <ItemStyle BackColor="#EFF3FB" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <FooterTemplate> <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder> </FooterTemplate> </asp:DataList></div> <asp:TextBox ID="TextBox1" runat="server" Style="position: relative"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="position: relative" Text="填写想分页每页的项个数,并执行" /> </form></body></html> C#:---------------------------------------------------------SqlConnection con; SqlDataAdapter da; DataSet ds; public int Pagesize { get { return Convert.ToInt32(Session["page"]); } set { Session["page"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int n=0; if (Request.QueryString["page"] != "") { n = Convert.ToInt32(Request.QueryString["page"]); } else { n = 0; } Bind(n); } } public void Bind(int n) { this.DataList1.DataSource = pds(n); this.DataList1.DataBind(); } public DataSet GetData(string sql) { con = new SqlConnection("server=.;uid=sa;pwd=;database=pubs"); da = new SqlDataAdapter(sql,con); ds = new DataSet(); da.Fill(ds); return ds; } public PagedDataSource pds() { PagedDataSource pds = new PagedDataSource(); pds.DataSource = GetData("select * from authors").Tables[0].DefaultView; pds.AllowPaging = true; pds.PageSize = Pagesize; return pds; } public PagedDataSource pds(int n) { PagedDataSource pds = new PagedDataSource(); pds.DataSource = GetData("select * from authors").Tables[0].DefaultView; pds.AllowPaging = true; pds.PageSize = Pagesize; pds.CurrentPageIndex = n; return pds; } protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Footer) { PlaceHolder ph = (PlaceHolder)e.Item.FindControl("ph"); for (int i = 0; i < pds().PageCount; i++) { HyperLink hp = new HyperLink(); Literal li = new Literal(); int n = i + 1; hp.ID = n.ToString(); hp.Text = n.ToString(); hp.NavigateUrl = "?page=" + i.ToString(); li.Text = " "; ph.Controls.Add(hp); ph.Controls.Add(li); } } } protected void Button1_Click(object sender, EventArgs e) { Session["page"] = Convert.ToInt32(TextBox1.Text); Bind(0); string str = Request.Url.ToString().Substring(0,21); Response.Write(str); } 上面的代码直接沾过去试试连接的库是sqlserver2000中默认的pubs库 RadioButtonList 提示出错 三层中业务逻辑层也定义个接口层好不好? 急!!!求助!关于GridView中模版列的问题 站点如何禁止粘贴复制拖入等 求高手指导菜鸟做个小网页 GridView采用XmlDataSource作为数据源,不支持更新和删除方法,如何解决? 业务逻辑层和表示层具体该怎么分离才好??--100分! 刚准备做一个B/S项目,必须问清楚一个简单但很重要的关于window.open()的经验问题 在线等:gridview第一列不能显示 IBM----急招-----快来看[公告] ----取货单,到库存中查询货架取货问题---格式测试 谁帮小妹一个忙?
------------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" Style="position: relative" RepeatDirection="Horizontal" CellPadding="4" ForeColor="#333333" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<table style="width: 100px; position: relative">
<tr>
<td>
<asp:Label ID="lblauid" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_id") %>'></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label ID="lblaufname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_fname") %>'></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label ID="lblaucity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"city") %>'></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label ID="lblauzip" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"zip") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#EFF3FB" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<FooterTemplate>
<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
</FooterTemplate>
</asp:DataList></div>
<asp:TextBox ID="TextBox1" runat="server" Style="position: relative"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="position: relative"
Text="填写想分页每页的项个数,并执行" />
</form>
</body>
</html>
---------------------------------------------------------
SqlConnection con;
SqlDataAdapter da;
DataSet ds; public int Pagesize
{
get
{
return Convert.ToInt32(Session["page"]);
}
set
{
Session["page"] = value;
}
} protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int n=0;
if (Request.QueryString["page"] != "")
{
n = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
n = 0;
}
Bind(n);
}
} public void Bind(int n)
{
this.DataList1.DataSource = pds(n);
this.DataList1.DataBind();
} public DataSet GetData(string sql)
{
con = new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
da = new SqlDataAdapter(sql,con);
ds = new DataSet();
da.Fill(ds);
return ds;
} public PagedDataSource pds()
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = GetData("select * from authors").Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = Pagesize;
return pds;
} public PagedDataSource pds(int n)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = GetData("select * from authors").Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = Pagesize;
pds.CurrentPageIndex = n;
return pds;
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
PlaceHolder ph = (PlaceHolder)e.Item.FindControl("ph");
for (int i = 0; i < pds().PageCount; i++)
{
HyperLink hp = new HyperLink();
Literal li = new Literal(); int n = i + 1;
hp.ID = n.ToString();
hp.Text = n.ToString();
hp.NavigateUrl = "?page=" + i.ToString();
li.Text = " ";
ph.Controls.Add(hp);
ph.Controls.Add(li);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["page"] = Convert.ToInt32(TextBox1.Text);
Bind(0);
string str = Request.Url.ToString().Substring(0,21);
Response.Write(str);
}
连接的库是sqlserver2000中默认的pubs库