.net repeater的用法
<divclass="bbstextline"> &...
<div class="bbstextline"> <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> </asp:Repeater> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT TOP 6 [zp_title] FROM [t5cms_jobinfo]"> </asp:SqlDataSource> </div> 绑定数据源了啊,怎么用,急啊,谢谢各位了!
展开
3个回答
2015-07-06 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464983
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
获取分页数据方法(多个排序字段)
/// <summary>
/// 获取分页数据(多个排序字段)
/// </summary>
/// <param name="pageSize">页面大小</param>
/// <param name="pageIndex">当前页索引</param>
/// <param name="recordCount">记录数</param>
/// <param name="where">查询条件</param>
/// <returns></returns>
public DataTable GetListManyOrderFile(int pageIndex, int pageSize, string table, string orderField, int orderType, string where, string key, out int recordCount)
{
if (where == null)
where = "";
OpenConn();
SqlCommand cmd = new SqlCommand("P_Page_ManyOrderFile", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@tblName", SqlDbType.VarChar, 800);
cmd.Parameters["@tblName"].Value = table;
cmd.Parameters.Add("@fldName", SqlDbType.VarChar, 255);
cmd.Parameters["@fldName"].Value = orderField;
cmd.Parameters.Add("@OrderType", SqlDbType.TinyInt);
cmd.Parameters["@OrderType"].Value = orderType;
cmd.Parameters.Add("pageIndex", SqlDbType.Int);
cmd.Parameters["pageIndex"].Value = pageIndex;
cmd.Parameters.Add("pageSize", SqlDbType.TinyInt);
cmd.Parameters["pageSize"].Value = pageSize;
cmd.Parameters.Add("strWhere", SqlDbType.VarChar, 1500);
cmd.Parameters["strWhere"].Value = where;
cmd.Parameters.Add("@doCount", SqlDbType.TinyInt);
cmd.Parameters["@doCount"].Value = 0;
cmd.Parameters.Add("@key", SqlDbType.VarChar,255);
cmd.Parameters["@key"].Value = key;
SqlDataAdapter DA = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DA.Fill(ds);
conn.Close();
conn.Dispose();
recordCount = GetRecordCount(table, where);
return ds.Tables[0];
}
返回记录数
/// <summary>
/// 返回记录数
/// </summary>
/// <param name="table">表名</param>
/// <param name="where">查询条件</param>
/// <returns></returns>
public int GetRecordCount(string table, string where)
{
int RecordCount = 0;
OpenConn();
SqlCommand cmd = new SqlCommand("TZFX_ZHDD_P_Page", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@tblName", SqlDbType.VarChar, 800);
cmd.Parameters["@tblName"].Value = table;
cmd.Parameters.Add("strWhere", SqlDbType.VarChar, 1500);
cmd.Parameters["strWhere"].Value = where;
cmd.Parameters.Add("@doCount", SqlDbType.TinyInt);
cmd.Parameters["@doCount"].Value = 1;
cmd.Prepare();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
RecordCount = int.Parse(dr[0].ToString());
}
//conn.Close();
//conn.Dispose();
dr.Close();
dr.Dispose();
return RecordCount;
}
获取分页数据存储过程(多个排序字段)
USE [表名]
GO
/****** Object: StoredProcedure [dbo].[P_Page_ManyOrderFile] Script Date: 03/06/2013 09:32:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[P_Page_ManyOrderFile]
@tblName varchar(800), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount tinyint=0, -- 返回记录总数, 非 0 值则返回
@OrderType tinyint = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1500) = '',-- 查询条件 (注意: 不要加 where)
@key varchar(255)-- 主键,用于分页
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 "+@strWhere
else
set @strSQL = "select count(*) as total from " + @tblName
--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
end
else
begin
if @OrderType != 0
begin
set @strTmp = " not in (select "
set @strOrder = " order by " + @fldName +" desc"
--如果@OrderType不是0,就执行降序,这句很重要!
end
else
begin
set @strTmp = " not in (select "
set @strOrder = " order by " + @fldName +" asc"
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ "
from " + @tblName + " where " + @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 [" + @key + "]" + @strTmp + "["+ @key + "]
from (select top " + str((@PageIndex-1)*@PageSize) + " ["+ @key + "]
from " + @tblName + @strOrder + ") as tblTmp)"+ @strOrder
if @strWhere !=''
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from "
+ @tblName + " where [" + @key + "]" + @strTmp + "["
+ @key + "] from (select top " + str((@PageIndex-1)*@PageSize) + " ["
+ @key + "] from " + @tblName + " where " + @strWhere + " "
+ @strOrder + ") as tblTmp) and " + @strWhere + " " + @strOrder
end
end
exec (@strSQL)
返回记录数存储过程
USE [表名]
GO
/****** Object: StoredProcedure [dbo].[TZFX_ZHDD_P_Page] Script Date: 03/06/2013 09:55:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[TZFX_ZHDD_P_Page]
@tblName varchar(800), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount tinyint=0, -- 返回记录总数, 非 0 值则返回
@OrderType tinyint = 0, -- 设置排序类型, 非 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 "+@strWhere
else
set @strSQL = "select count(*) as total from " + @tblName
--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
end
else
begin
if @OrderType != 0
begin
set @strTmp = "<(select min"
set @strOrder = " order by [" + @fldName +"] desc"
--如果@OrderType不是0,就执行降序,这句很重要!
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 " + @strWhere + " " + @strOrder
else
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ "
from "+ @tblName + @strOrder
--如果是第一页就执行以上代码,这样会加快执行速度
end
else
beginwww.2cto.com
--以下代码赋予了@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 " + @strWhere + " "
+ @strOrder + ") as tblTmp) and " + @strWhere + " " + @strOrder
end
end
exec (@strSQL)
/// <summary>
/// 获取分页数据(多个排序字段)
/// </summary>
/// <param name="pageSize">页面大小</param>
/// <param name="pageIndex">当前页索引</param>
/// <param name="recordCount">记录数</param>
/// <param name="where">查询条件</param>
/// <returns></returns>
public DataTable GetListManyOrderFile(int pageIndex, int pageSize, string table, string orderField, int orderType, string where, string key, out int recordCount)
{
if (where == null)
where = "";
OpenConn();
SqlCommand cmd = new SqlCommand("P_Page_ManyOrderFile", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@tblName", SqlDbType.VarChar, 800);
cmd.Parameters["@tblName"].Value = table;
cmd.Parameters.Add("@fldName", SqlDbType.VarChar, 255);
cmd.Parameters["@fldName"].Value = orderField;
cmd.Parameters.Add("@OrderType", SqlDbType.TinyInt);
cmd.Parameters["@OrderType"].Value = orderType;
cmd.Parameters.Add("pageIndex", SqlDbType.Int);
cmd.Parameters["pageIndex"].Value = pageIndex;
cmd.Parameters.Add("pageSize", SqlDbType.TinyInt);
cmd.Parameters["pageSize"].Value = pageSize;
cmd.Parameters.Add("strWhere", SqlDbType.VarChar, 1500);
cmd.Parameters["strWhere"].Value = where;
cmd.Parameters.Add("@doCount", SqlDbType.TinyInt);
cmd.Parameters["@doCount"].Value = 0;
cmd.Parameters.Add("@key", SqlDbType.VarChar,255);
cmd.Parameters["@key"].Value = key;
SqlDataAdapter DA = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DA.Fill(ds);
conn.Close();
conn.Dispose();
recordCount = GetRecordCount(table, where);
return ds.Tables[0];
}
返回记录数
/// <summary>
/// 返回记录数
/// </summary>
/// <param name="table">表名</param>
/// <param name="where">查询条件</param>
/// <returns></returns>
public int GetRecordCount(string table, string where)
{
int RecordCount = 0;
OpenConn();
SqlCommand cmd = new SqlCommand("TZFX_ZHDD_P_Page", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@tblName", SqlDbType.VarChar, 800);
cmd.Parameters["@tblName"].Value = table;
cmd.Parameters.Add("strWhere", SqlDbType.VarChar, 1500);
cmd.Parameters["strWhere"].Value = where;
cmd.Parameters.Add("@doCount", SqlDbType.TinyInt);
cmd.Parameters["@doCount"].Value = 1;
cmd.Prepare();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
RecordCount = int.Parse(dr[0].ToString());
}
//conn.Close();
//conn.Dispose();
dr.Close();
dr.Dispose();
return RecordCount;
}
获取分页数据存储过程(多个排序字段)
USE [表名]
GO
/****** Object: StoredProcedure [dbo].[P_Page_ManyOrderFile] Script Date: 03/06/2013 09:32:23 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[P_Page_ManyOrderFile]
@tblName varchar(800), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount tinyint=0, -- 返回记录总数, 非 0 值则返回
@OrderType tinyint = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1500) = '',-- 查询条件 (注意: 不要加 where)
@key varchar(255)-- 主键,用于分页
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 "+@strWhere
else
set @strSQL = "select count(*) as total from " + @tblName
--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
end
else
begin
if @OrderType != 0
begin
set @strTmp = " not in (select "
set @strOrder = " order by " + @fldName +" desc"
--如果@OrderType不是0,就执行降序,这句很重要!
end
else
begin
set @strTmp = " not in (select "
set @strOrder = " order by " + @fldName +" asc"
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ "
from " + @tblName + " where " + @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 [" + @key + "]" + @strTmp + "["+ @key + "]
from (select top " + str((@PageIndex-1)*@PageSize) + " ["+ @key + "]
from " + @tblName + @strOrder + ") as tblTmp)"+ @strOrder
if @strWhere !=''
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from "
+ @tblName + " where [" + @key + "]" + @strTmp + "["
+ @key + "] from (select top " + str((@PageIndex-1)*@PageSize) + " ["
+ @key + "] from " + @tblName + " where " + @strWhere + " "
+ @strOrder + ") as tblTmp) and " + @strWhere + " " + @strOrder
end
end
exec (@strSQL)
返回记录数存储过程
USE [表名]
GO
/****** Object: StoredProcedure [dbo].[TZFX_ZHDD_P_Page] Script Date: 03/06/2013 09:55:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[TZFX_ZHDD_P_Page]
@tblName varchar(800), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount tinyint=0, -- 返回记录总数, 非 0 值则返回
@OrderType tinyint = 0, -- 设置排序类型, 非 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 "+@strWhere
else
set @strSQL = "select count(*) as total from " + @tblName
--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
end
else
begin
if @OrderType != 0
begin
set @strTmp = "<(select min"
set @strOrder = " order by [" + @fldName +"] desc"
--如果@OrderType不是0,就执行降序,这句很重要!
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 " + @strWhere + " " + @strOrder
else
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ "
from "+ @tblName + @strOrder
--如果是第一页就执行以上代码,这样会加快执行速度
end
else
beginwww.2cto.com
--以下代码赋予了@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 " + @strWhere + " "
+ @strOrder + ") as tblTmp) and " + @strWhere + " " + @strOrder
end
end
exec (@strSQL)
展开全部
我们一般不 是这样用的。 <asp:Repeater runat="server" ID="CustRep" OnItemDataBound="CustRep_ItemDataBound">
<ItemTemplate>
//中间绑定数据也可以写html 代码
<%#Eval("Cust_ContactMan") %>
</ItemTemplate>
</asp:Repeater>
后台只要
CustRep.DataSource = custTable;//custtable是你查询返回的结果集可以是datatable,也可以是dataset
CustRep.DataBind();
<ItemTemplate>
//中间绑定数据也可以写html 代码
<%#Eval("Cust_ContactMan") %>
</ItemTemplate>
</asp:Repeater>
后台只要
CustRep.DataSource = custTable;//custtable是你查询返回的结果集可以是datatable,也可以是dataset
CustRep.DataBind();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在页面中放一个Repeater 控件 里面有ItemTemplate节点 用表达式<%# 表达式%>指定你要绑定的数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询