1

我目前被困在如何在另一个页面中显示我的网格数据。

基本上我有一个启用分页的 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();

    }
}
4

1 回答 1

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();

}
于 2012-11-17T15:10:34.843 回答