用的gridview的allowpaging属性自动分页,有查询功能。在点击页码事件中我重新绑定了查询后的结果集,但是我刷新页面,显示结果仍为查询结果。。
protected void Page_Load(object sender, EventArgs e)
{
//Session["isSearch"] = null;
bindFreight();//自定义方法
} protected void bindFreight()
{
string sql = "select * from cargo";
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.DataBind();
} protected void gvFreight_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string sql;
sql = Convert.ToString(Session["searchSql"]);
if (sql==null)
{
gvFreight.PageIndex = e.NewPageIndex;
gvFreight.DataBind();
}
else
{
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.PageIndex = e.NewPageIndex;
gvFreight.DataBind();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string table ="cargo";
string keyType1 = "ID";
string keyType2 = "terminal";
string keyType3 = "date";
string keyType4 = "trainNumber";
string key1 = orderID.Text;
string key2 = terminal.Text;
string key3 = leaveDate.Text;
string key4 = trainNumber.Text;
string sql;
if (key1 != "" || key2 != "" || key3 != "" || key4 != "")
{
sql = "select * from " + table + " where " + keyType1 + " like '%" + key1 + "%' and " + keyType2 + " like '%" + key2 + "%' and " + keyType3 + " like '%" + key3 + "%' and " + keyType4 + " like '%" + key4 + "%'";//
Session["searchSql"] = sql;
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.DataBind();
//Session["searchType"] = ddlSearchType.SelectedValue.ToString();
}
else
{
sql="";
RegisterStartupScript("false", "<script>alert('请输入查询条件!')</script>");
}
}
gridview分页
protected void Page_Load(object sender, EventArgs e)
{
//Session["isSearch"] = null;
bindFreight();//自定义方法
} protected void bindFreight()
{
string sql = "select * from cargo";
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.DataBind();
} protected void gvFreight_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string sql;
sql = Convert.ToString(Session["searchSql"]);
if (sql==null)
{
gvFreight.PageIndex = e.NewPageIndex;
gvFreight.DataBind();
}
else
{
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.PageIndex = e.NewPageIndex;
gvFreight.DataBind();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string table ="cargo";
string keyType1 = "ID";
string keyType2 = "terminal";
string keyType3 = "date";
string keyType4 = "trainNumber";
string key1 = orderID.Text;
string key2 = terminal.Text;
string key3 = leaveDate.Text;
string key4 = trainNumber.Text;
string sql;
if (key1 != "" || key2 != "" || key3 != "" || key4 != "")
{
sql = "select * from " + table + " where " + keyType1 + " like '%" + key1 + "%' and " + keyType2 + " like '%" + key2 + "%' and " + keyType3 + " like '%" + key3 + "%' and " + keyType4 + " like '%" + key4 + "%'";//
Session["searchSql"] = sql;
gvFreight.DataSource = dataOperate.getDataset(sql, "cargo"); //调用getDataset方法将返回值绑定到GridView上
gvFreight.DataBind();
//Session["searchType"] = ddlSearchType.SelectedValue.ToString();
}
else
{
sql="";
RegisterStartupScript("false", "<script>alert('请输入查询条件!')</script>");
}
}
gridview分页
解决方案 »
- 帮我注释一下DBHelper
- showModalDialog 弹出窗口问题
- 这个flash是怎样读取数据的??
- aspx首页不显示的原因
- 图片在DataGird中显示出错,代码如下。
- 从数据库中读取二进制数据,转换成图片文件时怎样做数据的存在性检查
- DataGrid中加入"修改","删除"列为什么运行时不起作用? 还有加入"分页"也不起作用!!
- 我用SqlReader读取select的结果总是不成功,请大家帮帮忙呀!!
- 怎么去除textbox中录入的非法字符,如单引号'、<a>之类的标签等等....
- 急求助在visual studio.net 2003 中不能创建asp.net 工程的问题!!急急急!!
- ASP.NET自定义用户如何取值?高分求大神,急急急急急急急急急急急急急急急急!
- 关于gridview绑定数据问题,通过变量关联
{
if(!ISPostBack)
{
bindFreight();//自定义方法
}
}
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
if (!IsPostBack)
{}你这样做的目的是 查询中也有分页?
加了这个后,查询前点击第二页会报错,ExecuteReader: CommandText 属性尚未初始化;而查询后刷新页面还是只显示查询结果。。
{
去掉代码
}
你直接写翻页的查询,然后把数据填充GridView。查询的时候使用子查询,来查询固定位置的固定数目sql记录。
select top n * from Table where id not in (select top m id from Table)