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中去
}
}
}
查看全文
相关阅读:
10 个迅速提升你 Git 水平的提示
GitLab-CI与GitLab-Runner
WEB应用安全解决方案测试验证
sparse representation 与sparse coding 的区别的观点
The Ph.D. Grind
Potential Pythonic Pitfalls
Overfitting & Regularization
LVM的一般操作过程
你跟大牛之间仅仅差一个google
Hadoop伪分布式模式部署
原文地址:https://www.cnblogs.com/thcjp/p/739486.html
最新文章
为什么企业纷纷去重庆申请网络小贷公司牌照
牌照成鸡肋 传统小贷公司转型路在何方
地方财力比拼:广东破万亿居首 相当于11省份总和
The Mathematics of the Rubik’s Cube
PowerShell Gallery
powershell脚本的格式化
powershell的stable和preview版本
外键 Foreign keys
100. Same Tree
Is it bad to rely on foreign key cascading? 外键 级联操作
热门文章
How can I list all foreign keys referencing a given table in SQL Server?
The DELETE statement conflicted with the REFERENCE constraint
876. Middle of the Linked List
Pull Request的正确打开方式(如何在GitHub上贡献开源项目)
使用git、git-flow与gitlab工作
git如何删除远程仓库的某次错误提交
git diff命令详解
git stash 命令
git clean用法
git命令之git tag 给当前分支打标签
Copyright © 2011-2022 走看看