.net gridview 存储过程高效分页代码!
.netgridview存储过程高效分页代码!简单点的也行!但必须完整!本人正在初学中,好多看不懂的!谢谢!先谢谢各位了,我要全部的代码,还有,数据库我是SQL2000的...
.net gridview 存储过程高效分页代码!
简单点的也行!但必须完整! 本人正在初学中,好多看不懂的!谢谢!
先谢谢各位了,我要全部的代码,还有,数据库我是SQL 2000的! 展开
简单点的也行!但必须完整! 本人正在初学中,好多看不懂的!谢谢!
先谢谢各位了,我要全部的代码,还有,数据库我是SQL 2000的! 展开
3个回答
展开全部
_Default.aspx中的代码
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None" onpageindexchanging="GridView1_PageIndexChanging">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="产品名称" HeaderText="产品名称" />
相应的cs代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = Class1.colsemission("select * from 产品");
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Class1.colsemission("select * from 产品");
GridView1.DataBind();
}
<asp:TemplateField HeaderText="供应商">
<ItemTemplate>
无忧人-<%# Eval("产品名称")%>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField DataImageUrlField="产品图片" HeaderText="产品图片">
<ControlStyle Height="100px" Width="100px" />
</asp:ImageField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
数据库连结的通用类不用写了把?
gridview主要用了allowpageing=属性和PageIndexChanging()事件就可以做出翻页的效果~!
/// <summary>
/// 打开数据库的公共访问类
/// </summary>
public class Class1
{
/// <summary>
/// 连结字符串
/// </summary>
public static string str = System.Configuration.ConfigurationSettings.AppSettings["Tstr"].ToString();
/// <summary>
/// 连结模式(增删改)
/// </summary>
/// <param name="sql">执行的SQl语句</param>
public static void relatemission(string sql)
{
using (OleDbConnection conn=new OleDbConnection(str))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql,conn);
cmd.ExecuteReader();
conn.Close();
}
}
/// <summary>
/// 断开模式(查)
/// </summary>
/// <param name="sql">执行的SQl语句</param>
/// <returns>返回数据集</returns>
public static DataTable colsemission(string sql)
{
DataTable dt = new DataTable();
using (OleDbConnection conn=new OleDbConnection(str))
{
OleDbDataAdapter dda = new OleDbDataAdapter(sql,conn);
dda.Fill(dt);
}
return dt;
}
}
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None" onpageindexchanging="GridView1_PageIndexChanging">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="产品名称" HeaderText="产品名称" />
相应的cs代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = Class1.colsemission("select * from 产品");
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = Class1.colsemission("select * from 产品");
GridView1.DataBind();
}
<asp:TemplateField HeaderText="供应商">
<ItemTemplate>
无忧人-<%# Eval("产品名称")%>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField DataImageUrlField="产品图片" HeaderText="产品图片">
<ControlStyle Height="100px" Width="100px" />
</asp:ImageField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
数据库连结的通用类不用写了把?
gridview主要用了allowpageing=属性和PageIndexChanging()事件就可以做出翻页的效果~!
/// <summary>
/// 打开数据库的公共访问类
/// </summary>
public class Class1
{
/// <summary>
/// 连结字符串
/// </summary>
public static string str = System.Configuration.ConfigurationSettings.AppSettings["Tstr"].ToString();
/// <summary>
/// 连结模式(增删改)
/// </summary>
/// <param name="sql">执行的SQl语句</param>
public static void relatemission(string sql)
{
using (OleDbConnection conn=new OleDbConnection(str))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql,conn);
cmd.ExecuteReader();
conn.Close();
}
}
/// <summary>
/// 断开模式(查)
/// </summary>
/// <param name="sql">执行的SQl语句</param>
/// <returns>返回数据集</returns>
public static DataTable colsemission(string sql)
{
DataTable dt = new DataTable();
using (OleDbConnection conn=new OleDbConnection(str))
{
OleDbDataAdapter dda = new OleDbDataAdapter(sql,conn);
dda.Fill(dt);
}
return dt;
}
}
展开全部
SqlServer2005的解法
select *,ROW_NUMBER() OVER(ORDER BY OrderField DESC) as ROWNUMBER from TableA where ROWNUMBER <25 and ROWNUMBER >1.
select *,ROW_NUMBER() OVER(ORDER BY OrderField DESC) as ROWNUMBER from TableA where ROWNUMBER <25 and ROWNUMBER >1.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分页事件:
gvPoList_PageIndexChanging
调用这个方法之后,设定gv.PageIndex = e.NewPageIndex;
然后重新绑定数据
gvPoList_PageIndexChanging
调用这个方法之后,设定gv.PageIndex = e.NewPageIndex;
然后重新绑定数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询