public DataView myBind() //定义的数据绑定
{ //建立数据连接
string str = System.Configuration.ConfigurationManager.AppSettings["strconn"];
SqlConnection conn = new SqlConnection(str);
SqlDataAdapter sdr = new SqlDataAdapter("select * from CustomerInfo where ShowType=" + DrpShowType.SelectedValue + " order by ID desc", conn);
DataSet ds = new DataSet();
sdr.Fill(ds, "CustomerInfo");
return ds.Tables["CustomerInfo"].DefaultView;
}
protected void btnSelect_Click(object sender, EventArgs e) //查询数据
{
if (txtSelect.Text == "")
{
Response.Write("<script>alert('请输入内容!')</script>");
this.GrdAds.DataSource = myBind();
this.GrdAds.DataBind();
return;
}
else
{
string str = System.Configuration.ConfigurationManager.AppSettings["strconn"];
SqlConnection conn = new SqlConnection(str); SqlDataAdapter sdr = new SqlDataAdapter("select * from CustomerInfo where " + Drpselect.SelectedValue + " like '%" + txtSelect.Text.ToString() + "%'", conn);
DataSet ds = new DataSet();
try
{
sdr.Fill(ds, "tt");
if (ds.Tables["tt"].Rows.Count != 0)
{
this.GrdAds.DataSource = ds.Tables["tt"].DefaultView;
this.GrdAds.DataBind();
}
else
{
Response.Write("<script>alert('没有相关记录!')</script>");
} }
catch (Exception ex)
{
throw ex;
}
}
}
//分页按钮
protected void GrdAds_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//获取当前显示页索引
GrdAds.PageIndex = e.NewPageIndex; //重新绑定
this.GrdAds.DataSource = myBind();
this.GrdAds.DataBind();
}
}我出现的问题是
我点击 查找按钮 button时,他会查出过很相关的记录如果记录一页显示不了,我点击第二页的时侯
他就重新绑定到初始的绑定了,并不是显示查找出来的第二页,怎么解决?
解决方案 »
- 关于在gridview中<edititemtemplate>里dropdownlist的动态赋值问题!
- datatable select 问题 在线急等。。。。
- 关于DropDownlist组合查询的问题
- vs2005express如何编译网站为一个Dll ----100分--------
- 求一正则表达式(30分)
- 关于IE缓存的疑问
- C#菜鸟的问题,如何使用Chr(),Asc()函数?
- 如何把js获得变量直接显示在html中?
- 我在asp.net中使用了自己定义的控件,为什么属性中的事件经常丢失?谢谢
- 一个奇怪的问题
- .aspx文件和.aspx.cs文件有什么区别?
- 推荐几个好的.net编辑器吧.感觉fck太大.freetextbox效果不是太好
你下面那个分页不管什么时候执行的一直是
public DataView myBind() //定义的数据绑定
{ //建立数据连接
string str = System.Configuration.ConfigurationManager.AppSettings["strconn"];
SqlConnection conn = new SqlConnection(str);
SqlDataAdapter sdr = new SqlDataAdapter("select * from CustomerInfo where ShowType=" + DrpShowType.SelectedValue + " order by ID desc", conn);
DataSet ds = new DataSet();
sdr.Fill(ds, "CustomerInfo");
return ds.Tables["CustomerInfo"].DefaultView;
}
这里面的查询
当你点击按钮查找后必须改变上面的 不然分不了
自己想想
我试着定义了 一个变量 i
当i=1public DataView myBind() //定义的数据绑定
{
if{i=1}
{
绑定1
}
else
{
绑定2
}
}但是 i怎么传值啊?
把你 btnSelect_Click中查询数据的代码放入mybind()里就对了.
那我之前的 mybind()代码放哪呢?
这段代码可以实现我其他情况下的分页
就查询出来的分页没办法实现.我看出问题出在mybind语句里面,
查询分页 调用mybind肯定错了
select * from CustomerInfo where ShowType=" + DrpShowType.SelectedValue + " order by ID desc", conn);
他的select语句是通过showType来查的,
但是我不知道怎么解决这个问题啊?
各位帮我想想办法啊?
我看了都没人给 我回帖
{ //建立数据连接
string str = System.Configuration.ConfigurationManager.AppSettings["strconn"];
SqlConnection conn = new SqlConnection(str);
string sql="";
if (txtSelect.Text == "")
{
sql="select * from CustomerInfo where ShowType=" + DrpShowType.SelectedValue + " order by ID desc";
}
else{
sql="select * from CustomerInfo where " + Drpselect.SelectedValue + " like '%" + txtSelect.Text.ToString() + "%'";
}
SqlDataAdapter sdr = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sdr.Fill(ds, "CustomerInfo");
return ds.Tables["CustomerInfo"].DefaultView;
} protected void btnSelect_Click(object sender, EventArgs e) //查询数据
{
this.GrdAds.DataSource = myBind();
this.GrdAds.DataBind();
}
//分页按钮
protected void GrdAds_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//获取当前显示页索引
GrdAds.PageIndex = e.NewPageIndex; //重新绑定
this.GrdAds.DataSource = myBind();
this.GrdAds.DataBind();
}
}
非常谢谢你
呵呵,
谢谢
值根本就不好在全局传 本来初始是1 执行到 查询时 赋为2
接下来执行到
if(!isposkback)
时i的值又是 1了
根本就实现不了啊