小妹真的要求帮忙了,火急啊~~~
我用datagrid来显示数据和分页
<asp:datagrid id="dgCustomer" runat="server" Width="100%" AutoGenerateColumns="False" AllowCustomPaging=True AllowPaging="True" PageSize="15" Height="127px" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" BackColor="White"
CellPadding="3" GridLines="Horizontal">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<tr style="cursor:hand" height="25" bgcolor="Honeydew" onclick="javascript:window.parent.window.returnValue='<%#
DataBinder.Eval(Container.DataItem, "emplyname")%>;<%#DataBinder.Eval(Container.DataItem, "emplyid")%>';window.parent.close();">
<td><%#DataBinder.Eval(Container.DataItem,"emplyid") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"emplyname") %></td>
</tr>
</ItemTemplate>
</asp:TemplateColumn>
</Columns></asp:datagrid>
cs中的代码:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
int id=0;
id=Convert.ToInt32(Request.QueryString["depart"].ToString());
Session["depart"]=id.ToString();
dgCustomer.CurrentPageIndex=0;
dgCustomer.VirtualItemCount=100;
bindgrid();
}
}
public void bindgrid()
{
string sql="select * from hr_emply where dptid='"+int.Parse(Session["depart"].ToString())+"'";
SqlCommand cm=new SqlCommand(sql,hr.conn);
cm.Connection.Open();
dgCustomer.DataSource=cm.ExecuteReader();
dgCustomer.DataBind();
currentPage.InnerHtml=(dgCustomer.CurrentPageIndex+1).ToString();
total.InnerHtml=(dgCustomer.PageCount).ToString();
cm.Connection.Close();
if(dgCustomer.PageCount==1)
{
previous.Enabled=false;
next.Enabled=false;
}
else{
if(dgCustomer.CurrentPageIndex==0&&dgCustomer.PageCount>1)
{
previous.Enabled=false;
next.Enabled=true;
}
else
{
if(dgCustomer.CurrentPageIndex==(dgCustomer.PageCount-1))
{
next.Enabled=false;
previous.Enabled=true;
}
else
{
previous.Enabled=true;
next.Enabled=true;
}
}
}
}
public void NavigationLink_OnClick(object sender,CommandEventArgs e)
{
switch(e.CommandName){
case "first":
dgCustomer.CurrentPageIndex=0;
break;
case"last":
dgCustomer.CurrentPageIndex=dgCustomer.PageCount-1;
break;
case"next":
dgCustomer.CurrentPageIndex=dgCustomer.CurrentPageIndex+1;
break;
case"previous":
dgCustomer.CurrentPageIndex=dgCustomer.CurrentPageIndex-1;
break;
}
bindgrid();
}
我出现的问题是翻页时当前页的显示数据也是对的,会加一,但是显示的数据始终为开始的几条记录,这是怎么回事啊,真的把我弄火了~~
问题点数:10、回复次数:3Top
1 楼oneway888(xiaoaoyisheng)回复于 2005-08-01 17:25:53 得分 0
page+1Top
2 楼fans869(fans869@china.com)回复于 2005-08-01 17:37:19 得分 0
你若是用Web Matrix,可以在Database里面选定带有SortingandPageing的,很简单都是它自动完成的.Top
3 楼daliboy()回复于 2005-08-01 17:55:52 得分 0
string sql="select * from hr_emply where dptid='"+int.Parse(Session["depart"].ToString())+"'"; 需要重写 ,再增加一个条件,即键
如select * from hr_emply where dptid=... and id>PageIndex and id<PageIndex*Pagesixe
这个意思,试试吧!Top




