我现在停留在如何在另一个页面中显示我的网格数据。
基本上我有一个启用了分页的GridView名称“gdvRiders”。问题是当我点击第2页时,我得到一个没有数据的空白页面。有人能帮我吗?我开始学习c#
了这是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
DataBase db = new DataBase(true);
string strSQL;
DataTable dt;
if (!IsPostBack)
{
strSQL = "SELECT r.surname, r.firstname, cn.country, r.age, f.flagurl " +
"FROM (Riders r INNER JOIN par_CountryNation cn ON r.countryid = cn.countryid) INNER JOIN par_Flags f ON cn.flagid = f.flagid ";
dt = db.getDataTableAc(strSQL, "list_Riders");
gdvRiders.DataSource = dt;
gdvRiders.DataBind();
}
}
protected void gdvRiders_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdvRiders.PageIndex = e.NewPageIndex;
gdvRiders.DataBind();
}
}
答案 0 :(得分:1)
您需要将数据分配给网格的数据源。 You should put the code to bind the gridview in separate function and call it from page_load and PageIndexChanging.
protected void gdvRiders_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
strSQL = "SELECT r.surname, r.firstname, cn.country, r.age, f.flagurl " +
"FROM (Riders r INNER JOIN par_CountryNation cn ON r.countryid = cn.countryid) INNER JOIN par_Flags f ON cn.flagid = f.flagid ";
dt = db.getDataTableAc(strSQL, "list_Riders");
gdvRiders.PageIndex = e.NewPageIndex;
gdvRiders.DataSource = dt;
gdvRiders.DataBind();
}