DataGrid怎样进行分页,点击下一页的时候没有显示数据???
publicpartialclassstudent_list:System.Web.UI.Page{protectedvoidPage_Load(objectsender...
public partial class student_list : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sql;
sql = "select * from xuesheng order by id asc";
getdata(sql);
}
}
private void getdata(string sql)
{
DataSet result = new DataSet();
result = new Class1().hsggetdata(sql);
if (result != null)
{
if (result.Tables[0].Rows.Count > 0)
{
DataGrid1.DataSource = result.Tables[0];
DataGrid1.DataBind();
Label1.Text = "以上数据中共" + result.Tables[0].Rows.Count + "条";
}
else
{
DataGrid1.DataSource = null;
DataGrid1.DataBind();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql;
sql = "select * from xuesheng where 1=1";
if (bh.Text.ToString().Trim() != "")
{
sql = sql + " and xuehao = '" + bh.Text.ToString().Trim() + "'";
}
getdata(sql);
}
protected void PageChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}
} 展开
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sql;
sql = "select * from xuesheng order by id asc";
getdata(sql);
}
}
private void getdata(string sql)
{
DataSet result = new DataSet();
result = new Class1().hsggetdata(sql);
if (result != null)
{
if (result.Tables[0].Rows.Count > 0)
{
DataGrid1.DataSource = result.Tables[0];
DataGrid1.DataBind();
Label1.Text = "以上数据中共" + result.Tables[0].Rows.Count + "条";
}
else
{
DataGrid1.DataSource = null;
DataGrid1.DataBind();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql;
sql = "select * from xuesheng where 1=1";
if (bh.Text.ToString().Trim() != "")
{
sql = sql + " and xuehao = '" + bh.Text.ToString().Trim() + "'";
}
getdata(sql);
}
protected void PageChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询