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中去
}
}
}
查看全文
相关阅读:
使用PHP获取用户客户端真实IP的解决方案
PHP中使用mkdir创建多级目录的方法
javascript中将字符串转换为json格式的三种方法
Codeigniter处理用户登录验证后URL跳转
PHP正则表达式匹配URL中的域名
开源项目列表
PG JDBC COPY感谢原作者
if中return的用法
读数据库查询的 ResultSet时java.sql.SQLException: 流已被关闭
一篇讲JAVA JDBC的好文章
原文地址:https://www.cnblogs.com/thcjp/p/739486.html
最新文章
利用thrift实现js与C#通讯的例子
VS2012在给js下断点时,突然断点失效,以及应急办法。
javascript / js / jquery的HtmlEncode
Thrift问题集合,打算用Thrift作为生产工具的先看看这个
使用jquery,按id复制节点,并更改该节点id,以及更改该节点下的已知节点id
LayoutInflater.from()和LayoutInflater.inflate()方法
GridView 滑动到底部时加载新数据
SSHFQ工具使用
IBM编写多线程的 Java 应用程序
使用 Java 测试网络连通性的几种方法
热门文章
ImageView MaxWidht
View 局部刷新 是注意
ListView控件 数据加载
理解参数是按值而不是按引用传递的
Ksoap SoapPrimitive 与 SoapObject
Javascript实现类似PHP的print_r函数
js中字符串数据转为json对象的方法
PHP中文字符串截断无乱码解决方案
Codeigniter CRUD代码快速构建
源生javascript 添加getElementByClass方法
Copyright © 2011-2022 走看看