This is a migrated thread and some comments may be shown as answers.

Data Source Null when Paging

1 Answer 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kate
Top achievements
Rank 1
Kate asked on 14 Aug 2012, 07:57 PM
Hi All,

I'm having some issues building a RadGrid using Advanced Data Binding.  I have a grid that is displaying a report that's run by selection options and clicking a button.  When the button is clicked the first page generates correctly, but any time you try to use any of the paging (click page number, forward, back) the DataSourse appears to be wiped out and the grid becomes invisible again since it is empty.  Any help would be appreciated.

Grid:
<telerik:RadGrid ID="GridComplianceReport" Width="100%" 
     AllowPaging="True" PageSize="30" runat="server" AllowSorting="true" Visible="false" 
     OnNeedDataSource="GridComplianceReport_NeedDataSource" GridLines="None" >
     <MasterTableView Width="100%" />
     <PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>

OnNeedDataSource:
protected void GridComplianceReport_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    Employee parentEmployee = new Employee();
    Employee childEmployee = new Employee();
    if (Session["Employee"] != null)
    {
        parentEmployee = (Employee)Session["Employee"];
    }
    if (Session["ChildEmployee"] != null)
    {
        childEmployee = (Employee)Session["ChildEmployee"];
        if (Session["SelectedEmployeeID"].ToString() == parentEmployee.EmployeeID)
        {
            FillComplianceReport(parentEmployee);
        }
        else
        {
            FillComplianceReport(childEmployee);
        }
    }
    else //no child employee, populate with logged in employee
    {
        FillComplianceReport(parentEmployee);
    }
}
private void FillComplianceReport(Employee employee)
{
    lblReportsHeader.Text = employee.Name;
    string who = "";
    ArrayList complianceType = new ArrayList();
    ArrayList complianceStatus = new ArrayList();
    List<Reports> complianceReport = new List<Reports>();
    who = rdbEmployeeType.SelectedItem.Value;
    foreach (ListItem item in chkComplianceTypes.Items)
    {
        if (item.Selected)
            complianceType.Add(item.Value);
    }
    foreach (ListItem item in chkComplianceStatus.Items)
    {
        if (item.Selected)
            complianceStatus.Add(item.Value);
    }
    complianceReport = EmployeeBLL.GetComplianceReports(employee.EmployeeID, who, complianceType, complianceStatus);
    Session["ComplianceReport"] = complianceReport;
    GridComplianceReport.DataSource = complianceReport;
    if (compliancereport.Count > 0)
        GridComplianceReport.Visible = true;
    ReportsExceptionPanel.Visible = false;
}
On Button Click:
protected void btnGenerateComplianceReport_Click(object sender, ImageClickEventArgs e)
{
    GridComplianceReport.Visible = true;
    GridComplianceReport.DataSource = null;
    GridComplianceReport.Rebind();
}

1 Answer, 1 is accepted

Sort by
0
Kate
Top achievements
Rank 1
answered on 15 Aug 2012, 06:08 PM
Solved this with reference to this post.
Tags
Grid
Asked by
Kate
Top achievements
Rank 1
Answers by
Kate
Top achievements
Rank 1
Share this question
or