我用Repeater做了分页,如果不加搜索的话是正常的
由于数据比较多,后来我在此页面加了一个搜索框,
<asp:TextBox id=Keyword runat= "server "> </asp:TextBox>
如果网页第一次加载,且我不按下一页的时候,搜索功能是正常能用的.
如果我按了下一页或者下一页,搜索功能搜出来的就是空的.
我想应该是数据绑定的问题,所以请教应该如何重新绑定,或者帮我看看是不是这个问题.新人手上没分,请原谅
以后是我代码. protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookies = Request.Cookies["oUserName"];
if (cookies == null)
{
Response.Redirect("Close_Cookies.aspx");
}
databind(); } private void databind()
{
try
{
string url="Ks_manage.aspx",sql;
//string urlstr = "Keyword='+Keyword+'";
sql = "select * from ks_content where id <> 0";
if (this.Keyword.Text != "")
{
sql =sql+" and title like '%"+this.Keyword.Text+"%'";
}
SqlConnection conn = DB.conn();
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
conn.Open();
DataSet ds = new DataSet();
sda.Fill(ds, "table");
PagedDataSource objpage = new PagedDataSource();
objpage.DataSource = ds.Tables["table"].DefaultView;
objpage.AllowPaging = true;
objpage.PageSize = 12;
int curPage;
if (Request.QueryString["Page"] != null)
curPage = Convert.ToInt32(Request.QueryString["Page"]);
else
curPage = 1;
objpage.CurrentPageIndex = curPage - 1;
this.Label1.Text = "当前页:第" + curPage.ToString() + "页";
this.Label2.Text="共"+objpage.PageCount+"页";
if (!objpage.IsFirstPage)
{
this.HyperLink3.NavigateUrl = url + "?page=1";
this.HyperLink1.NavigateUrl=url+"?page="+Convert.ToInt32(curPage-1)+"";
}
if (!objpage.IsLastPage)
{
this.HyperLink2.NavigateUrl=url+"?page="+Convert.ToInt32(curPage+1)+"";
this.HyperLink4.NavigateUrl=url+"?page="+Convert.ToInt32(objpage.PageCount)+"";
}
this.Repeater1.DataSource = objpage;
this.Repeater1.DataBind();
conn.Close();
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
}
由于数据比较多,后来我在此页面加了一个搜索框,
<asp:TextBox id=Keyword runat= "server "> </asp:TextBox>
如果网页第一次加载,且我不按下一页的时候,搜索功能是正常能用的.
如果我按了下一页或者下一页,搜索功能搜出来的就是空的.
我想应该是数据绑定的问题,所以请教应该如何重新绑定,或者帮我看看是不是这个问题.新人手上没分,请原谅
以后是我代码. protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookies = Request.Cookies["oUserName"];
if (cookies == null)
{
Response.Redirect("Close_Cookies.aspx");
}
databind(); } private void databind()
{
try
{
string url="Ks_manage.aspx",sql;
//string urlstr = "Keyword='+Keyword+'";
sql = "select * from ks_content where id <> 0";
if (this.Keyword.Text != "")
{
sql =sql+" and title like '%"+this.Keyword.Text+"%'";
}
SqlConnection conn = DB.conn();
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
conn.Open();
DataSet ds = new DataSet();
sda.Fill(ds, "table");
PagedDataSource objpage = new PagedDataSource();
objpage.DataSource = ds.Tables["table"].DefaultView;
objpage.AllowPaging = true;
objpage.PageSize = 12;
int curPage;
if (Request.QueryString["Page"] != null)
curPage = Convert.ToInt32(Request.QueryString["Page"]);
else
curPage = 1;
objpage.CurrentPageIndex = curPage - 1;
this.Label1.Text = "当前页:第" + curPage.ToString() + "页";
this.Label2.Text="共"+objpage.PageCount+"页";
if (!objpage.IsFirstPage)
{
this.HyperLink3.NavigateUrl = url + "?page=1";
this.HyperLink1.NavigateUrl=url+"?page="+Convert.ToInt32(curPage-1)+"";
}
if (!objpage.IsLastPage)
{
this.HyperLink2.NavigateUrl=url+"?page="+Convert.ToInt32(curPage+1)+"";
this.HyperLink4.NavigateUrl=url+"?page="+Convert.ToInt32(objpage.PageCount)+"";
}
this.Repeater1.DataSource = objpage;
this.Repeater1.DataBind();
conn.Close();
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
}
解决方案 »
- 什么是航信配置呀?????
- ViewState到底该什么时候使用?我做为查询时保存查询条件
- 在数据库操作中,修改数据库中记录,遇到的一个问题......
- 如何打印页面的指定区域?
- RE: 趣味题:__*_=___=_*__ (备注:其中"_"为一个数字,数字为1-9,但不能重复) 用程序写出结果
- 小弟是初学者,问一个简单的问题,问题解决,立即给分
- datagrid 汇总?
- ListBox关联的问题/(高手请进)
- 这句话是谁输出的?
- 在HttpModule中截获Application的各种事件和在global.asax中Application事件中处理有何不同?
- 如何限制textbox控制输入必须是数值,并且不允许为空?
- QQ书签的实现
sql =sql+ " and title like '% "+this.Keyword.Text+ "% ' ";
___这里多了个空格