邮箱[email protected] 好使后就给分!谢谢!
解决方案 »
- 无法在发送 HTTP 标头之后进行重定向
- 这个LINQ怎么写?
- 匹配由4-15个数字、26个英文字母或者下划线组成的字符串的正则表达式
- 我用excel控件生成excel文件,只能生成一部分数据,好像数据多了,它生成不了
- asp.net中如何让程序暂停几秒后继续执行.
- 怎样修改这段web.config文件
- 一个asp.net与sql server2000数据库连接的一个问题,内祥,很急,请务必帮我,谢谢
- 水晶报表10企业版问题:在预览的时候点导出, 打开一个导出页面,是英文的,如何改成中文?
- public static string 和 static public string 有什么区别
- Entity Framework. The query must be of type ObjectQuery or DbQuery.
- 设置<forms name=".aspx" loginUrl="Default.aspx" protection="All" timeout="60"/>,现在有一个页面如(Default2.aspx)不想经过Default.aspx页面就可以直接访问?
- |zyciis| 工行的支付设计问题 如何更新本地的订单支付状态 第二贴 用户支付判断改为用AJAX去判断并在页面显示, 控制台信息如何制作多线程
<table> <tr> <td>
<a href="View.aspx?id=<%#Eval("id") %>"><%#Eval("Titel") %></a> </td> <td>
<%#Eval("Time").ToString().Substring(0, 9)%></font>
</td> </tr>
</td>
</table> </ItemTemplate> </asp:Repeater><table> <tr><td align="center"> <asp:LinkButton ID="lbtnFirstPage" runat="server" OnClick="lbtnFirstPage_Click">首页</asp:LinkButton> <asp:LinkButton ID="lbtnpritPage" runat="server" OnClick="lbtnLastPage_Click">上一页</asp:LinkButton> <asp:LinkButton ID="lbtnNextPage" runat="server" OnClick="lbtnNextPage_Click">下一页</asp:LinkButton> <asp:LinkButton ID="lbtnDownPage" runat="server" OnClick="lbtnFinalPage_Click">尾页</asp:LinkButton>第<asp:Label ID="labPage" runat="server" Text="Label"></asp:Label>页/共<asp:Label ID="LabCountPage" runat="server" Text="Label"></asp:Label>页 共<asp:Label ID="Total" runat="server" />条新闻</td></tr> </table>
后台CS代码:
protected void Page_Load(object sender, EventArgs e) { SqlConnection Conn = new SqlConnection(sqlcon); Conn.Open(); SqlCommand Cmd = new SqlCommand("select * from NewClass where id=" + Request.QueryString["id"], Conn);//取出从主页面中的Repeater控件传过来的id值(主页面导航条中的分类id) SqlDataReader sdr= Cmd.ExecuteReader(); if (Dr.Read()) { HiddenField1.Value = sdr["id"].ToString();//用HiddenField1控件来存放id的值,pageSource要用到这个值 } Conn.Close(); if (!IsPostBack) { this.labPage.Text = "1"; pageSource();//调用pageSource方法 } SqlConnection R_Conn = new SqlConnection(sqlcon); SqlDataAdapter R_sda = new SqlDataAdapter("select top 10 * from NewView order by Time desc", R_Conn); DataSet R_sda = new DataSet(); R_Da.Fill(R_sda, "NewView"); PagedDataSource Pds = new PagedDataSource(); Pds.DataSource = R_sda.Tables["NewView"].DefaultView; Pds.AllowPaging = true; Pds.PageSize = 25; R_Repeater.DataSource = Pds; R_Repeater.DataBind(); } //分页 public void pageSource() { SqlConnection Conn = new SqlConnection(sqlcon); SqlDataAdapter sda = new SqlDataAdapter("select * from NewView where Class_id=" + HiddenField1.Value + "order by id desc", Conn); DataSet Ds = new DataSet(); Da.Fill(Ds, "NewView"); PagedDataSource pds = new PagedDataSource(); pds.DataSource = Ds.Tables["NewView"].DefaultView; pds.AllowPaging = true; pds.PageSize = 10; Total.Text = pds.Count.ToString(); pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1; Repeater1.DataSource = pds; LabCountPage.Text = pds.PageCount.ToString(); labPage.Text = (pds.CurrentPageIndex + 1).ToString(); this.lbtnFirstPage.Enabled = true; this.lbtnLastPage.Enabled = true; this.lbtnNextPage.Enabled = true; this.lbtnFinalPage.Enabled = true; if (pds.CurrentPageIndex < 1)//如果页索引小于1,则首页和上一页按钮不显示 { this.lbtnFirstPage.Enabled = false; this.lbtnLastPage.Enabled = false; } if (pds.CurrentPageIndex == pds.PageCount - 1)//如果页索引为最后一页,也就是总页数减1,则尾页和下一页按钮不显示 { this.lbtnNextPage.Enabled = false; this.lbtnDownPage.Enabled = false; } Repeater1.DataBind(); } protected void lbtnLastPage_Click(object sender, EventArgs e) { this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1); pageSource(); } protected void lbtnFirstPage_Click(object sender, EventArgs e) { this.labPage.Text = "1"; pageSource(); } protected void lbtnFinalPage_Click(object sender, EventArgs e) { this.labPage.Text = this.LabCountPage.Text; pageSource(); } protected void lbtnNextPage_Click(object sender, EventArgs e) { this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1); pageSource(); }
<%@ Page Language="C#" MasterPageFile="~/admin/header_footer.master" AutoEventWireup="true" CodeFile="editPrice.aspx.cs" Inherits="admin_editPrice" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td style="text-align: center;">
价格信息</td>
</tr>
<tr>
<td style="text-align: center; height: 139px;">
<asp:DataList ID="DataList1" runat="server" OnCancelCommand="DataList1_CancelCommand" OnEditCommand="DataList1_EditCommand" OnUpdateCommand="DataList1_UpdateCommand" OnDeleteCommand="DataList1_DeleteCommand">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 100px; height: 16px">
<asp:Label ID="Label1" runat="server" Text='<%# Bind("type_Id") %>'></asp:Label></td>
<td style="width: 100px; height: 16px">
<asp:Label ID="Label2" runat="server" Text='<%# Bind("type") %>'></asp:Label></td>
<td style="width: 100px; height: 16px">
<asp:Label ID="Label3" runat="server" Text='<%# Bind("price") %>'></asp:Label></td>
<td style="width: 100px; height: 16px">
<asp:Button ID="btnEdit" runat="server" Text="修改" OnClientClick="return confirm('确认要编辑吗?');" CommandName="Edit" CommandArgument=' <%# Eval( "price") %> ' /></td>
<td style="width: 100px; height: 16px">
<asp:Button ID="Button2" runat="server" Text="删除" OnClientClick="return confirm('确认要删除吗?');" CommandArgument='<%#Eval("type_Id") %>' CommandName="Delete" /></td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 100px; height: 12px;">
编号</td>
<td style="width: 100px; height: 12px;">
类型</td>
<td style="width: 100px; height: 12px;">
价格</td>
<td style="width: 100px; height: 12px;">
编辑</td>
<td style="width: 100px; height: 12px">
删除</td>
</tr>
</table>
</HeaderTemplate>
<EditItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 100px; height: 16px">
<asp:Label ID="Label1" runat="server" Text='<%# Bind("type_Id") %>'></asp:Label></td>
<td style="width: 100px; height: 16px">
<asp:Label ID="Label2" runat="server" Text='<%# Bind("type") %>'></asp:Label></td>
<td style="width: 100px; height: 16px">
<asp:TextBox ID="tbPrice" runat="server" Text='<%# Bind("price") %>' Width="50px"></asp:TextBox></td>
<td style="width: 100px; height: 16px">
<asp:Button ID="btnUpdate" runat="server" Text="更新" CommandArgument='<%# Eval("type_Id") %> ' CommandName="Update" /></td>
<td style="width: 100px; height: 16px">
<asp:Button ID="btnCancel" runat="server" Text="取消" CommandName="Cancel" /></td>
</tr>
</table>
</EditItemTemplate>
</asp:DataList>
<asp:Label ID="lbCount" runat="server" Text="lbCount"></asp:Label>
<asp:Label ID="lbTotalPage" runat="server" Text="lbTotalPage"></asp:Label>
<asp:Label ID="lbCurPage" runat="server" Text="lbCurPage"></asp:Label> <asp:HyperLink
ID="hlnkHead" runat="server">首页</asp:HyperLink>
<asp:HyperLink ID="hlnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="hlnkNext" runat="server">下一页</asp:HyperLink>
<asp:HyperLink ID="hlnkEnd" runat="server">尾页</asp:HyperLink>
</td>
</tr>
<tr>
<td style="text-align: left">
在这里你也可以添加相关的类型,并对其进行价格录入。</td>
</tr>
<tr>
<td style="text-align: center">
类型添加:<asp:TextBox ID="tbType" runat="server"></asp:TextBox>
单价:<asp:TextBox ID="tbPrice" runat="server"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="添加" Width="58px" /></td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</asp:Content>
private void dListBindData()
{
string strCon = ConfigurationManager.AppSettings["SqlConnectionString"].ToString();
SqlConnection con = new SqlConnection(strCon);
SqlDataAdapter da = new SqlDataAdapter("select * from type", con);
DataSet ds = new DataSet();
try
{
con.Open();
//填充数据
da.Fill(ds, "type");
// 创建分页类
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource = ds.Tables["type"].DefaultView;
//设置总的查询结果
lbCount.Text = "总共有" + ds.Tables["type"].Rows.Count.ToString() + "条记录";
//设置可以分页以及每页的行数
objPage.AllowPaging = true;
objPage.PageSize = 6;
//总页数
lbTotalPage.Text = "总页数:" + objPage.PageCount.ToString() + "页";
//定义变量来保存当前页
int CurPage;
//判断是否具有页面跳转的请求
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
//设置当前页的索引
objPage.CurrentPageIndex = CurPage - 1;
lbCurPage.Text = "当前页 : 第" + CurPage.ToString() + "页";
//如果不是首页
if (!objPage.IsFirstPage)
{
//定义上一页超链接的url为: 当前执行页面的虚拟路径,并传递下一页面的索引值
hlnkHead.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
hlnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
}
//如果不是最后一页
if (!objPage.IsLastPage)
{
//定义“下一页”超链接url为:当前执行页面的虚拟路径,并传递下一页面的索引值
hlnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
hlnkEnd.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + objPage.PageCount.ToString();
}
DataList1.DataSource = objPage;
DataList1.DataBind();
con.Close();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
CREATE PROCEDURE testList --超强超简单的分页.条件是表中必须有一个字段(id)唯一值,可以按任一字段排序如name,age,sex等。版权所有ZKM_ZHANG 2008.09.17 欢迎联系[email protected]
@pageNow int, --begin=1
@pageSize int,
@recordCount int output
AS
declare @showCount int
set @showCount=@pageSize * @pageNow
select @recordCount=count(*) from test if (@recordCount % @pageSize)<>0 and (@pageNow = @recordCount / @pageSize + 1)
begin
set @pageSize=@recordCount % @pageSize
end
exec('select w.* from (select top ' + @pageSize + ' a.* from test a inner join (select top ' + @showCount + ' id from test order by age,id) b on a.id=b.id order by a.age desc,a.id desc) w order by w.age,w.id ')
http://download.csdn.net/source/660035
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=.;uid=sa;database=数据库");
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from Employees";
AspNetPager1.AlwaysShow=true;
AspNetPager1.PageSize=15;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection("server=.;uid=sa;database=数据库");
dr = new SqlDataAdapter("select * from Employees", con);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Employees");
DataList1.DataSource = ds.Tables["Employees"];
DataList1.DataBind(); } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataListDataBind();
}
AllowPaging="True" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
EmptyDataText="没有数据记录!!" AllowSorting="True" Height="111px" Width="764px">
<Columns>
<asp:BoundField DataField="Work_group_name" FooterText="公司信息" HeaderText="公司信息" HtmlEncode="False"
SortExpression="公司信息" ItemStyle-Width ="400px"/>
<asp:BoundField DataField="cMemo" FooterText="业务员" HeaderText="业务员" HtmlEncode="False"
这是存储过程哦:
create procedure paging
(
@index int,--当前页索引
@size int,--每页大小
@count int output--目标表中记录总数
)
as
--创建临时表temp,解决目标表(本例中是products)中主键值可能不连续问题
create table #temp
(
idnew int identity(1,1),
idold int
)
--从目标表中查询出主键值,插入到临时表中
insert into #temp select productid from products
--通过与临时表temp进行内连接,从目标表中查出所需记录
select productid,productname,unitprice from products
inner join #temp on productid=idold
where #temp.idnew>(@index-1)*@size and #temp.idnew<=@index*@size
--给输出参数@count赋值
set @count=(select count(*) from products)
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
总共有<asp:Label ID="lblTotal" runat="server" Font-Bold="True"></asp:Label>页 当前为第<asp:Label ID="lblCurrentPage"
runat="server" ForeColor="Red"></asp:Label>页
<asp:LinkButton ID="firstPage" runat="server" OnClick="firstPage_Click">首页</asp:LinkButton>
<asp:LinkButton ID="previousPage" runat="server" OnClick="previousPage_Click">上 一页</asp:LinkButton>
<asp:LinkButton ID="nextPage" runat="server" OnClick="nextPage_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lastPage" runat="server" OnClick="lastPage_Click">末页</asp:LinkButton><br />
<table border="0" style="width: 100%">
<tr>
<td bgcolor="#ffcc66" align="center">
GridView 分页</td>
<td bgcolor="#ffcc66" align="center">
DataList分页</td>
<td bgcolor="#ffcc66" align="center">
Repeater分页</td>
</tr>
<tr>
<td valign="top" width="350px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="productid" HeaderText="产品编号" />
<asp:BoundField DataField="productname" HeaderText="产品名称" />
<asp:BoundField DataField="unitprice" HeaderText="产品价格" />
</Columns>
</asp:GridView>
</td>
<td valign="top" width="350px">
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
产品编号:<asp:Label ID="Label1" runat="server" Text='<%# Eval("productid") %>'></asp:Label><br />
产品名称:<asp:Label ID="Label2" runat="server" Text='<%# Eval("productname")%>'></asp:Label><br />
产品价格:<asp:Label ID="Label3" runat="server" Text='<%# Eval("unitprice") %>'></asp:Label>
</ItemTemplate>
</asp:DataList></td>
<td valign="top" width="400px">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
产品编号:<%# Eval("productid") %><br/>
产品名称:<%# Eval("productname") %><br/>
产品价格:<%# Eval("unitprice") %><br/>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
这是后台的主要代码:
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
} int index = 1;//当前页索引
int size = 5;//每页大小(记录条数)
protected void Bind()
{
//创建连接对象
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=;database=northwind");
//创建数据适配器对象(命令字符串为存储过程paging,连接对象为con)
SqlDataAdapter sda = new SqlDataAdapter("paging", con);
//指定SelectCommand类型为存储过程
sda.SelectCommand.CommandType = CommandType.StoredProcedure; //创建参数数组
SqlParameter[] parames = new SqlParameter[] {
new SqlParameter("@index",SqlDbType.Int),
new SqlParameter("@size",SqlDbType.Int),
new SqlParameter("@count",SqlDbType.Int)
}; //设置每个参数的值以及参数方向
parames[0].Value = index;
parames[1].Value = size;
parames[2].Direction = ParameterDirection.Output;
//为sda对象的SelectCommand添加参数
foreach (SqlParameter param in parames)
{
sda.SelectCommand.Parameters.Add(param);
} //创建数据集对象ds
DataSet ds = new DataSet();
//执行命令,将执行结果填充到数据集对象ds
sda.Fill(ds); //获取被查询表中记录总数
int count = Convert.ToInt32(sda.SelectCommand.Parameters["@count"].Value); //设置总页数(总记录数除以每页大小)
if (count % size == 0)
{
lblTotal.Text = Convert.ToString(count / size);
}
else
{//如果除不断,总页数为商+1
lblTotal.Text = Convert.ToString(count / size + 1);
} //设置当前页索引
lblCurrentPage.Text = index.ToString(); //将数据集ds绑定到GridView,DataList,Repeater
GridView1.DataSource = ds;
GridView1.DataBind(); DataList1.DataSource = ds;
DataList1.DataBind(); Repeater1.DataSource = ds;
Repeater1.DataBind(); //设置“首页”等连接的可用状态
SetLinkButtonState();
} //定义方法SetLinkButtonState用来设置“首页”等连接的可用状态
protected void SetLinkButtonState()
{
if (lblTotal.Text == "1")
{//如果总页数只有一页,则全部设为不可用
firstPage.Enabled = false;
previousPage.Enabled = false;
nextPage.Enabled = false;
lastPage.Enabled = false;
}
else
{//否则,总页数不止一页
if (lblCurrentPage.Text == lblTotal.Text)
{//如果当前页是最后一页,则启用“首页”“上一页”,禁用“末页”“下一页”
firstPage.Enabled = true;
previousPage.Enabled = true;
nextPage.Enabled = false;
lastPage.Enabled = false;
}
else if (lblCurrentPage.Text == "1")
{//如果当前页是第一页,则禁用“首页”“上一页”,启用“末页”“下一页”
firstPage.Enabled = false;
previousPage.Enabled = false;
nextPage.Enabled = true;
lastPage.Enabled = true;
}
else
{//如果既不是第一页,又不是最后一页,则启用全部LinkButton
firstPage.Enabled = true;
previousPage.Enabled = true;
nextPage.Enabled = true;
lastPage.Enabled = true;
}
}
} //首页
protected void firstPage_Click(object sender, EventArgs e)
{
index = 1;
Bind();
} //上一页
protected void previousPage_Click(object sender, EventArgs e)
{
index = int.Parse(lblCurrentPage.Text) - 1;
Bind();
} //下一页
protected void nextPage_Click(object sender, EventArgs e)
{
index = int.Parse(lblCurrentPage.Text) + 1;
Bind();
} //末页
protected void lastPage_Click(object sender, EventArgs e)
{
index = int.Parse(lblTotal.Text);
Bind();
}
}这是分页的存储过程:
create procedure paging
(
@index int,--当前页索引
@size int,--每页大小
@count int output--目标表中记录总数
)
as
--创建临时表temp,解决目标表(本例中是products)中主键值可能不连续问题
create table #temp
(
idnew int identity(1,1),
idold int
)
--从目标表中查询出主键值,插入到临时表中
insert into #temp select productid from products
--通过与临时表temp进行内连接,从目标表中查出所需记录
select productid,productname,unitprice from products
inner join #temp on productid=idold
where #temp.idnew>(@index-1)*@size and #temp.idnew<=@index*@size
--给输出参数@count赋值
set @count=(select count(*) from products)
回家要好好理解哦不要COPY就行了哦,不懂得时候在访问我吧,我会把我懂得都告诉你!