用户分页控件绑定repeater控件
自己创建一个用户分页控件,后要和repeater控件绑定,但是repeater控件的名称不一定,该如何用此分类控件绑定不同的repeater控件?repeater控件不是...
自己创建一个用户分页控件,后要和repeater控件绑定,但是repeater控件的名称不一定,该如何用此分类控件绑定不同的repeater控件?
repeater控件不是用户控件内的,和分页控件不是同一页,repeater是XX.aspx中的并且不止一页每页的repeater控件不知道具体的数量和名称 展开
repeater控件不是用户控件内的,和分页控件不是同一页,repeater是XX.aspx中的并且不止一页每页的repeater控件不知道具体的数量和名称 展开
3个回答
展开全部
给你个存储过程
CREATE PROCEDURE [dbo].[P_newpager]
@tblname VARCHAR(255), -- 表名
@strGetFields nvarchar(1000) = "*", -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回, 非值则返回记录总数
@OrderType bit = 0, -- 设置排序类型, 非值则降序
@strWhere varchar(1500) = '' -- 查询条件(注意: 不要加where)
AS
declare @strSQL varchar(5000) -- 主语句
declare @strTmp varchar(110) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @doCount != 0
begin
if @strWhere !=''
set @strSQL = 'select count(*) as Total from [' + @tblName + '] where 1=1 '+ @strWhere
else
set @strSQL = 'select count(*) as Total from [' + @tblName + ']'
end --以上代码的意思是如果@doCount传递过来的不是,就执行总数统计。以下的所有代码都是@doCount为的情况:
else
begin
if @OrderType != 0--降序
begin
set @strTmp = '<(select min'
set @strOrder = ' order by [' + @fldName +'] desc'--如果@OrderType不是,就执行降序,这句很重要!
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @fldName +'] asc'
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) +' ' + @strGetFields + ' from [' + @tblName + '] where 1=1 ' + @strWhere + ' ' + @strOrder
else
set @strSQL = 'select top ' + str(@PageSize) +' ' + @strGetFields + ' from [' + @tblName + '] ' + @strOrder--如果是第一页就执行以上代码,这样会加快执行速度
end
else
begin--以下代码赋予了@strSQL以真正执行的SQL代码
set @strSQL = 'select top ' + str(@PageSize) + ' ' + @strGetFields + ' from [' + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [' + @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)' + @strOrder
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from [' + @tblName + '] where [' + @fldName + ']' + @strTmp + '([' + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [' + @fldName + '] from [' + @tblName + '] where 1=1 ' + @strWhere + ' ' + @strOrder + ') as tblTmp) and 1=1 ' + @strWhere + ' ' + @strOrder
end
if @strWhere !='' --得到记录的总行数
set @strSQL =@strSQL+ '; select count(*) as Total from [' + @tblName + '] where 1=1 '+ @strWhere
else
set @strSQL =@strSQL+ '; select count(*) as Total from [' + @tblName + ']'
end
exec (@strSQL)
RETURN
执行存储过程
exec [P_newpager]'bpis_patient_info','patient_id,patient_name,patient_sex','patient_id','10','2','0','0',''
CREATE PROCEDURE [dbo].[P_newpager]
@tblname VARCHAR(255), -- 表名
@strGetFields nvarchar(1000) = "*", -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回, 非值则返回记录总数
@OrderType bit = 0, -- 设置排序类型, 非值则降序
@strWhere varchar(1500) = '' -- 查询条件(注意: 不要加where)
AS
declare @strSQL varchar(5000) -- 主语句
declare @strTmp varchar(110) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @doCount != 0
begin
if @strWhere !=''
set @strSQL = 'select count(*) as Total from [' + @tblName + '] where 1=1 '+ @strWhere
else
set @strSQL = 'select count(*) as Total from [' + @tblName + ']'
end --以上代码的意思是如果@doCount传递过来的不是,就执行总数统计。以下的所有代码都是@doCount为的情况:
else
begin
if @OrderType != 0--降序
begin
set @strTmp = '<(select min'
set @strOrder = ' order by [' + @fldName +'] desc'--如果@OrderType不是,就执行降序,这句很重要!
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @fldName +'] asc'
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) +' ' + @strGetFields + ' from [' + @tblName + '] where 1=1 ' + @strWhere + ' ' + @strOrder
else
set @strSQL = 'select top ' + str(@PageSize) +' ' + @strGetFields + ' from [' + @tblName + '] ' + @strOrder--如果是第一页就执行以上代码,这样会加快执行速度
end
else
begin--以下代码赋予了@strSQL以真正执行的SQL代码
set @strSQL = 'select top ' + str(@PageSize) + ' ' + @strGetFields + ' from [' + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [' + @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)' + @strOrder
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from [' + @tblName + '] where [' + @fldName + ']' + @strTmp + '([' + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [' + @fldName + '] from [' + @tblName + '] where 1=1 ' + @strWhere + ' ' + @strOrder + ') as tblTmp) and 1=1 ' + @strWhere + ' ' + @strOrder
end
if @strWhere !='' --得到记录的总行数
set @strSQL =@strSQL+ '; select count(*) as Total from [' + @tblName + '] where 1=1 '+ @strWhere
else
set @strSQL =@strSQL+ '; select count(*) as Total from [' + @tblName + ']'
end
exec (@strSQL)
RETURN
执行存储过程
exec [P_newpager]'bpis_patient_info','patient_id,patient_name,patient_sex','patient_id','10','2','0','0',''
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class content : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["lzy"]);
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
num.Text = "1";
bind();
}
}
private void bind()
{
string select = "select * from News where program='" + Request.QueryString["program"] + "' order by time desc";
SqlDataAdapter sda = new SqlDataAdapter(select, conn);
sda.Fill(ds, "program");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource = ds.Tables["program"].DefaultView;
objPage.AllowPaging = true;
objPage.PageSize = 16;
int curpage = Convert.ToInt32(num.Text);
this.BtnDown.Enabled = true;
this.BtnUp.Enabled = true;
objPage.CurrentPageIndex = curpage - 1;
if (curpage == 1)
{
this.BtnUp.Enabled = false;
}
if (curpage == objPage.PageCount)
{
this.BtnDown.Enabled = false;
}
total.Text = objPage.PageCount.ToString();
this.Repeater1.DataSource = objPage;
this.Repeater1.DataBind();
}
protected void BtnUp_Click(object sender, EventArgs e)
{
this.num.Text = Convert.ToString(Convert.ToInt32(num.Text) - 1);
bind();
}
protected void BtnDown_Click(object sender, EventArgs e)
{
this.num.Text = Convert.ToString(Convert.ToInt32(num.Text) + 1);
bind();
}
源:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table width="100%">
<tr>
<td align="center" style="width:20%"><a target="_parent" href="content-detailed.aspx?title=<%# Eval("title") %>"><%# SubString(Eval("title").ToString()) %></a></td>
<td align="left" style="width:70%"><u><%# Substring(Eval("content").ToString()) %></u></td>
<td align="center" style="width:10%"><%# Eval("time","{0:yyyy-MM-dd}") %></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<div style="text-align: center">
当前页:<asp:Label ID="num" runat="server"></asp:Label>
<asp:Button ID="BtnUp" runat="server" onclick="BtnUp_Click" Text="上一页"
BackColor="White" BorderStyle="None" ForeColor="Black" />
<asp:Button ID="BtnDown" runat="server" onclick="BtnDown_Click" Text="下一页"
BackColor="White" BorderStyle="None" ForeColor="Black" />
总页数:<asp:Label ID="total" runat="server"></asp:Label>
</div>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class content : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["lzy"]);
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
num.Text = "1";
bind();
}
}
private void bind()
{
string select = "select * from News where program='" + Request.QueryString["program"] + "' order by time desc";
SqlDataAdapter sda = new SqlDataAdapter(select, conn);
sda.Fill(ds, "program");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource = ds.Tables["program"].DefaultView;
objPage.AllowPaging = true;
objPage.PageSize = 16;
int curpage = Convert.ToInt32(num.Text);
this.BtnDown.Enabled = true;
this.BtnUp.Enabled = true;
objPage.CurrentPageIndex = curpage - 1;
if (curpage == 1)
{
this.BtnUp.Enabled = false;
}
if (curpage == objPage.PageCount)
{
this.BtnDown.Enabled = false;
}
total.Text = objPage.PageCount.ToString();
this.Repeater1.DataSource = objPage;
this.Repeater1.DataBind();
}
protected void BtnUp_Click(object sender, EventArgs e)
{
this.num.Text = Convert.ToString(Convert.ToInt32(num.Text) - 1);
bind();
}
protected void BtnDown_Click(object sender, EventArgs e)
{
this.num.Text = Convert.ToString(Convert.ToInt32(num.Text) + 1);
bind();
}
源:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table width="100%">
<tr>
<td align="center" style="width:20%"><a target="_parent" href="content-detailed.aspx?title=<%# Eval("title") %>"><%# SubString(Eval("title").ToString()) %></a></td>
<td align="left" style="width:70%"><u><%# Substring(Eval("content").ToString()) %></u></td>
<td align="center" style="width:10%"><%# Eval("time","{0:yyyy-MM-dd}") %></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<div style="text-align: center">
当前页:<asp:Label ID="num" runat="server"></asp:Label>
<asp:Button ID="BtnUp" runat="server" onclick="BtnUp_Click" Text="上一页"
BackColor="White" BorderStyle="None" ForeColor="Black" />
<asp:Button ID="BtnDown" runat="server" onclick="BtnDown_Click" Text="下一页"
BackColor="White" BorderStyle="None" ForeColor="Black" />
总页数:<asp:Label ID="total" runat="server"></asp:Label>
</div>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分页控件加个方法不就行了
public void showthanklist(DataTable dt, Repeater Repeater1)
{
PagedDataSource pagedata = new PagedDataSource();
pagedata .DataSource=dt.DefaultView;
pagedata.PageSize = ...;
pagedata.AllowPaging = true;
.....
Repeater1.DataSource = pagedata;
Repeater1.DataBind();
}
public void showthanklist(DataTable dt, Repeater Repeater1)
{
PagedDataSource pagedata = new PagedDataSource();
pagedata .DataSource=dt.DefaultView;
pagedata.PageSize = ...;
pagedata.AllowPaging = true;
.....
Repeater1.DataSource = pagedata;
Repeater1.DataBind();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询