IListSource不包含任何数据源。在gridview中单击下一页时

问题描述 投票:0回答:1
Lbl_Username.Text = FirstName + " " + LastName;
    if (!IsPostBack)
    {
        ds = objSun.FetchTravelDetails(userId);
        int datasetcount = ds.Tables[0].Rows.Count;
        if (datasetcount == 0)
        {
            dt.Columns.Add("request_ID");
            dt.Columns.Add("userId");
            dt.Columns.Add("");
            dt.Columns.Add("status");
            dt.Columns.Add("remark");
            dt.Columns.Add("");
            for (int i = 0; i < 9; i++)
            {
                DataRow dr = dt.NewRow();
                dt.Rows.Add(dr);
            }
            GridView_RequisitionManagement.DataSource = dt;
            GridView_RequisitionManagement.DataBind();
        }
        else
        {
            GridView_RequisitionManagement.DataSource = ds;
            GridView_RequisitionManagement.DataBind();
        }
    } 
}

protected void GridView_RequisitionManagement_RowDataBound(object sender, GridViewRowEventArgs e)
{
    int datasetcount1 = ds.Tables[0].Rows.Count;
    if (datasetcount1 != 0)
    {
        for (int i = 0; i < GridView_RequisitionManagement.Rows.Count; i++)
        {
            LinkButton lnk_view = new LinkButton();
            lnk_view = GridView_RequisitionManagement.Rows[i].FindControl("LinkBtn_ViewFullDetails_GridView_LeaveManagement") as LinkButton;

            int type = Convert.ToInt32(ds.Tables[0].Rows[i]["request_Type"].ToString());
            string typeName = "";
            string requestId = GridView_RequisitionManagement.DataKeys[i][0].ToString();
            string request_userId = GridView_RequisitionManagement.DataKeys[i][1].ToString();
            switch (type)
            {
                case 2:
                    {
                        typeName = "Travel Request";
                        lnk_view.PostBackUrl = "Status_ViewDetails_TravelClaims.aspx?requestId=" + requestId;
                        break;
                    }
                case 3:
                    {
                        typeName = "Other Claims";
                        lnk_view.PostBackUrl = "Status_ViewDetails_OtherClaims.aspx?requestId=" + requestId;
                        break;
                    }
                case 4:
                    {
                        typeName = "Petty cash";
                        lnk_view.PostBackUrl = "Status_ViewDetails_PettyCashVoucher.aspx?requestId=" + requestId;
                        break;
                    }
                case 5:
                    {
                        typeName = "Advance";
                        lnk_view.PostBackUrl = "Status_ViewDetails_AdvanceRequisitions.aspx?requestId=" + requestId;
                        break;
                    }
            }
            GridView_RequisitionManagement.Rows[i].Cells[1].Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["date"].ToString()).ToShortDateString();
            GridView_RequisitionManagement.Rows[i].Cells[2].Text = typeName;
        }
    }
    else
    {
        for (int j = 0; j < GridView_RequisitionManagement.Rows.Count; j++)
        {
            GridViewRow rows = GridView_RequisitionManagement.Rows[j];
            LinkButton lnk_grd_views = (LinkButton)rows.FindControl("LinkBtn_ViewFullDetails_GridView_LeaveManagement") as LinkButton;
            lnk_grd_views.Visible = false;
        }
    }
}

protected void GridView_RequisitionManagement_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

    GridView_RequisitionManagement.PageIndex = e.NewPageIndex;
    GridView_RequisitionManagement.DataSource = ds;
    GridView_RequisitionManagement.DataBind();

}

大家好,我需要一些帮助。我正在使用上面的代码来显示详细信息 在

GridView
DataTable
DataSet
用于填充
GridView
。现在我想在
GridView
中进行分页,但是当单击下一页时,它会显示以下错误:

IListSource不包含任何数据源

网格中的下一页显示为空。

请协助我。

asp.net gridview pagination
1个回答
0
投票

似乎您只在不是回发时才设置数据集“ds”。因此,当运行 PageIndexChanging 事件时,ds 不会被设置为数据集。

尝试移动

ds = objSun.FetchTravelDetails(userId);

if(!IsPostback)
线上方。

© www.soinside.com 2019 - 2024. All rights reserved.