datagrid查询后分页(dataview分页)问题,一直解决不了...

jpuestc 2007-07-19 05:00:52
datagrid查询后分页问题,也就是dataview分页问题,比如:数据共100条,查询后应该为60条,但点下一页,上一页,或者首页或者尾页的时候又变成100条了。
代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MIS.core.rzcx;
using MIS.core;
using System.Text;


namespace MIS.XCRZ
{

public class InspectionList : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label lblPageCount;
protected System.Web.UI.WebControls.Label lblCurrentIndex;
protected System.Web.UI.WebControls.LinkButton btnFirst;
protected System.Web.UI.WebControls.LinkButton btnPrev;
protected System.Web.UI.WebControls.LinkButton btnNext;
protected System.Web.UI.WebControls.LinkButton btnLast;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected string District;
protected System.Web.UI.WebControls.Label Msg;
protected string uID,uname;
protected System.Web.UI.WebControls.DropDownList DropDownList1;

public DataSet eDs = new DataSet();
public DbPublic dbpub= new DbPublic();
protected rzcxVo rzcxvo = new rzcxVo();
protected rzcxDAO rzcxdao = new rzcxDAO();

protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
public string Fillter = "";


private void Page_Load(object sender, System.EventArgs e)
{
uID=Convert.ToString(Session["uID"]);
uname=Convert.ToString(Session["uname"]);
District = Convert.ToString(Session["uDistrict"]);

if(!IsPostBack)
{
try
{
TextBox1.Text= dbpub.myYMD();//2007-7-1
TextBox2.Text= DateTime.Now.ToShortDateString();
FillDropDownList();

Bind();
}
catch(Exception ex)
{
ex.Message.ToString();
}
}
}



private void FillDropDownList()
{
DropDownList1.DataSource=dbpub.LoadZhDdl(District);
DropDownList1.DataTextField="RoadName";
DropDownList1.DataValueField="ID";
DropDownList1.DataBind();

DropDownList2.DataSource=dbpub.LoadCaseListDW();
DropDownList2.DataTextField="DWName";
DropDownList2.DataValueField="DWId";
DropDownList2.DataBind();
}




//绑定页面字段,从数据库取数展示
private void Bind()
{

//当前分类下所有列表
eDs = rzcxdao.LoadList(uID,District);
eDs.Tables[0].Columns.Add("Info");
eDs.Tables[0].Columns.Add("Edit");
eDs.Tables[0].Columns.Add("Remove");
eDs.Tables[0].Columns.Add("Print");
for(int i=0;i<eDs.Tables[0].Rows.Count;i++)
{
eDs.Tables[0].Rows[i]["Info"] = "<a href=\"InspectionLogMdf.aspx?xcid=" + eDs.Tables[0].Rows[i]["xcid"].ToString()+ "&flag=ck" + "\">查看</a>";
eDs.Tables[0].Rows[i]["Edit"] = "<a href=\"InspectionLogMdf.aspx?xcid=" + eDs.Tables[0].Rows[i]["xcid"].ToString()+ "&flag=xg" + "\">修改</a>";
eDs.Tables[0].Rows[i]["Remove"] = "<a href=# onclick=del('xcrzRemove.aspx?xcid=" + eDs.Tables[0].Rows[i]["xcid"].ToString() + "')>删除</a>";
eDs.Tables[0].Rows[i]["Print"] = "<a href=\"../xcrz/report/InspectionLog.aspx?xcid=" + eDs.Tables[0].Rows[i]["xcid"].ToString() + "\"+ target=_blank>打印</a>";
}


DataView dvUK=new DataView(eDs.Tables[0]);
dvUK.RowFilter=Fillter;
DataGrid1.DataSource = dvUK;
Label1.Text = "记录总数: " + dvUK.Count.ToString() +"条";
DataGrid1.DataBind();
ShowStats();
}


private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("InspectionLog.aspx");
}

//显示分页信息,由PageButtonClick方法调用
private void ShowStats()
{
lblCurrentIndex.Text = "第"+(DataGrid1.CurrentPageIndex + 1).ToString() + "页";
lblPageCount.Text = "总" + DataGrid1.PageCount.ToString()+ "页";
}

private void PageButtonClick(object sender, System.EventArgs e)
{
string PageInfo = ((LinkButton)sender).CommandArgument.ToString();
switch (PageInfo)
{
case "next":
if(DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))
{
DataGrid1.CurrentPageIndex += 1;
}
break;

case "prev":
if(DataGrid1.CurrentPageIndex > 0)
{
DataGrid1.CurrentPageIndex -= 1;
}
break;

case "last":
DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1);
break;

default:
DataGrid1.CurrentPageIndex = Convert.ToInt32(PageInfo);
break;

}

Bind();

}



private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
Bind();
}

private void AddOrderID(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果当前项不为空
if(e.Item.ItemIndex != -1 )
{
//取得当前项的索引值加1,因为项的索引值是从0开始的.
int orderID =(DataGrid1.CurrentPageIndex)*
(DataGrid1.PageSize)+e.Item.ItemIndex+1;
//设置第一列为的单元格内容为当前项索引值加1
e.Item.Cells[0].Text = orderID.ToString();
}

if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem )
{
if(e.Item.Cells[5].Text!=uname)
{
e.Item.Cells[7].Text = "";
e.Item.Cells[8].Text = "";
}
}
}



private void del(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

string id;
//int num=0;
//num= eDs.Tables.Count;
//Tables[0].Rows.Count;
id=eDs.Tables[0].Rows[e.Item.DataSetIndex]["xcid"].ToString().Trim();
if("Delete" == e.CommandName)
{
Response.Redirect("xcrzRemove.aspx?xcid="+id);
}
}


private void Button1_Click(object sender, System.EventArgs e)
{

DateTime DateTime1=Convert.ToDateTime(TextBox1.Text.Trim());
DateTime DateTime2=Convert.ToDateTime(TextBox2.Text.Trim());
StringBuilder sbFilter = new StringBuilder();
Fillter = sbFilter.AppendFormat(" LogDate>'{0}' and LogDate<='{1}'",DateTime1,DateTime2).ToString();
if(DropDownList1.SelectedItem.Text.ToString()!="全部线路")
{
Fillter = Fillter + " and Section2 = '"+DropDownList1.SelectedItem.Text.ToString()+"'";
}
if(DropDownList2.SelectedItem.Text.ToString()!="全部单位")
{
Fillter = Fillter +" and WorkUnit = '"+DropDownList2.SelectedItem.Text.ToString()+"'";
}
DataGrid1.CurrentPageIndex = 0;
Bind();

}


}
}
...全文
236 回复 点赞 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2007-07-19 05:00
社区公告
暂无公告