zoukankan
html css js c++ java
为在母版页中的DataList脚模板中增加页码
其实很简单的一个问题,但是多了个母版页就容易把人绕进去.
简单来说就是忽略母版页的存在吧.
下面是主要的代码
全部代码下载
<%
@ Page Language
=
"
C#
"
MasterPageFile
=
"
~/mp.master
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
Default2
"
Title
=
"
Untitled Page
"
%>
<
asp:Content
ID
="Content1"
ContentPlaceHolderID
="ContentPlaceHolder1"
Runat
="Server"
>
<
asp:DataList
ID
="DataList1"
runat
="server"
BackColor
="White"
BorderColor
="#E7E7FF"
BorderStyle
="None"
BorderWidth
="1px"
CellPadding
="3"
DataKeyField
="id"
GridLines
="Horizontal"
OnItemCreated
="DataList1_ItemCreated"
>
<
FooterStyle
BackColor
="#B5C7DE"
ForeColor
="#4A3C8C"
/>
<
SelectedItemStyle
BackColor
="#738A9C"
Font-Bold
="True"
ForeColor
="#F7F7F7"
/>
<
ItemTemplate
>
id:
<
asp:Label
ID
="idLabel"
runat
="server"
Text
='<%#
Eval("id") %
>
'>
</
asp:Label
><
br
/>
name:
<
asp:Label
ID
="nameLabel"
runat
="server"
Text
='<%#
Eval("name") %
>
'>
</
asp:Label
><
br
/>
<
br
/>
</
ItemTemplate
>
<
AlternatingItemStyle
BackColor
="#F7F7F7"
/>
<
ItemStyle
BackColor
="#E7E7FF"
ForeColor
="#4A3C8C"
/>
<
HeaderStyle
BackColor
="#4A3C8C"
Font-Bold
="True"
ForeColor
="#F7F7F7"
/>
<
FooterTemplate
>
</
FooterTemplate
>
</
asp:DataList
><
br
/>
</
asp:Content
>
后台代码
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
public
partial
class
Default2 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
Bind();
}
private
void
Bind()
{
SqlConnection con
=
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"
temp
"
].ConnectionString);
PagedDataSource pds
=
new
PagedDataSource();
SqlDataAdapter sda
=
new
SqlDataAdapter(
"
select * from info
"
,con);
DataSet ds
=
new
DataSet();
sda.Fill(ds,
"
tabe
"
);
pds.DataSource
=
ds.Tables[
"
tabe
"
].DefaultView;
pds.AllowPaging
=
true
;
pds.CurrentPageIndex
=
0
;
pds.PageSize
=
5
;
DataList1.DataSource
=
pds;
DataList1.DataBind();
}
protected
void
DataList1_ItemCreated(
object
sender, DataListItemEventArgs e)
{
//
在创建行的时候触发的事件
if
(e.Item.ItemType
==
ListItemType.Footer)
{
//
判断是脚模板
PlaceHolder pl
=
new
PlaceHolder();
//
动态创建一个PlaceHolder用来装页码
e.Item.Controls.Add(pl);
//
把PlaceHolder增加到脚模板中去
Label lbl
=
new
Label();
//
new一个Label,当然,如果这要做页码的话,建议就做成linkbutton了,呵呵
lbl.Text
=
"
1
"
;
pl.Controls.Add(lbl);
//
把lbl增加到PlaceHolder中去
}
}
}
查看全文
相关阅读:
C#+Arcengine创建内存图层
Creating a Feature Set via C#
ArcGIS Server for JavaScript api安装部署
Lucene.Net 3.0.3如何从TokenStream中获取token对象
MMSEG 中文算法说明
java DotNet char 代码对应
Lucene.Net 3.0.3如何从TokenStream中获取token对象
java DotNet char 代码对应
9.7
9.6
原文地址:https://www.cnblogs.com/thcjp/p/739486.html
最新文章
2011年最热门的50个CSS3教程
22个实用的HTML5 CSS3表单开发教程
10 awesome jQuery snippets
Apache 的 httpd.conf 详解
Android的一些例子
24个为Web开发人员准备的CSS3实用教程
20个必看的jQuery的导航插件
常用SEO查询工具
120个非常优秀的CSS水平导航菜单
zookeeper
热门文章
mybatis 内部定义对象和集合
poj1015 Jury Compromise
CF 959E Mahmoud and Ehab and the xorMST
Luogu 2375 [NOI2014]动物园
Luogu 4135 作诗
poj1722 SUBTRACT
Luogu 3810 三维偏序
Luogu 1099 树网的核
C#+Arcengine创建内存图层
MMSEG 中文算法说明
Copyright © 2011-2022 走看看