关于girdview分页问题,在线等,急,给分!!!!!
protected void reset_Click1(object sender, EventArgs e){
titles.Text = "";
bodys.Text = "";
}
protected void search_Click1(object sender, EventArgs e)
{
if (titles.Text.Trim().Length > 0 || bodys.Text.Trim().Length > 0)
{ ///构建数据库连接和删除新闻的SQL语句
SqlConnection myConnection = new SqlConnection(DataBaseDB.ConnectionString);
String cmdText = "select Title,Body FROM News WHERE Title like '%" + titles.Text.Trim()+ "%'and Body like '%"+bodys.Text.Trim()+"%'";
SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
///打开数据库连接并执行删除操作
myConnection.Open();
SqlDataAdapter da = new SqlDataAdapter(cmdText, myConnection);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
myConnection.Close();
}
else
{
Response.Write("<script>alert(\"请先添加搜索内容!\")</script>");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
//引用刚才建立的数据源
GridView1.DataBind();
}
}
效果就是在点击第二页是需要再点击一下search才能出现第二页,为什么???????????????????????? --------------------编程问答-------------------- 在这个时间里写
protected void GridView1_PageIndexChanged(object sender, GridViewPageEventArgs e)
{
GridView1.DataBind();
} --------------------编程问答-------------------- mark
补充:.NET技术 , C#