We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid requires postback to populate.

Hi,
I am currently using the webforms 'Grid' control to visualise purchase approvals, and it seems I can only bind data after some kind of server side event. If I put a checkbox in, I can click the checkbox and populate my grid, but without a checkbox the grid displays as empty with no records.
Here Is my codebehind file

using System;

using System.Linq;

using Dapper;

using System.Collections.Generic;

using Models;

using Syncfusion.XlsIO;

using Syncfusion.EJ.Export;

 

public partial class ProjectApproval : BandPage

{

#region Sql

private readonly string GetApprovals = @"

select top 50

t.Approval_Ticket_ID,h.Approval_Ticket_History_ID, tt.Name [type], h.Approval_Stage_Date [action_date], c.Forename + ' ' + c.Surname [ActionedBy],

CASE h.Approval_Action

WHEN '1' THEN 'Approved'

WHEN '2' THEN 'Rejected'

WHEN '3' THEN 'Delegated to ' + del.Forename + ' ' + del.surname

ELSE 'Other'

END [Action],

t.Created_Date [ApprovalCreated],t.name [description],wa.EXT_Workpackage_ID,d.EXT_Purchase_Requisition_Form_Data_ID,

wp.Workpackage_Code,d.po_number

from Approval_Ticket_History h

LEFT JOIN Approval_Ticket t on h.Approval_Ticket_ID=t.Approval_Ticket_ID

LEFT JOIN Approval_Ticket_Type tt on t.Approval_Ticket_Type_ID=tt.Approval_Ticket_Type_ID

LEFT JOIN Contact c on h.Contact_ID =c.Contact_ID

LEFT JOIN Contact del on h.Delegate_ID =del.Contact_ID

LEFT JOIN EXT_Workpackage_Approval wa on t.Approval_Ticket_ID=wa.Approval_Ticket_ID

LEFT JOIN EXT_Workpackage wp on wa.EXT_Workpackage_ID=wp.EXT_Workpackage_ID

LEFT JOIN EXT_Purchase_Requisition_Form_Data d on t.Approval_Ticket_ID=d.approval_ticket

where

t.Entity_Class_ID=3 and t.Entity_Identifier=@Entity

order by h.Approval_Stage_Date desc";

#endregion Sql

public IEnumerable GetApprovalDetails(bool hideComplete)

{

using (var connection = ConnectionService.CreateConnection())

{

var approvals = connection.Query(GetApprovals, new { Entity = Entity.EntityID });

if (hideComplete)

{

approvals = approvals.ToList();

}

return approvals;

}

}

protected void Grid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)

{

BindGrid();

new ExcelExport().Export(Grid.Model, Grid.DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, ExportTheme.BootstrapTheme);

}

protected void hideComplete_Change(object Sender, Syncfusion.JavaScript.Web.CheckBoxEventArgs e)

{

BindGrid();

}

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

hideComplete.Checked = false;

BindGrid();

}

}

private void BindGrid()

{

Grid.DataSource = GetApprovalDetails(hideComplete.Checked);

Grid.DataBind();

}

}


1 Reply

VN Vignesh Natarajan Syncfusion Team February 22, 2019 03:04 AM

Hi Alex, 
 
Thanks for contacting Syncfusion support. 
 
Query: If I put a checkbox in, I can click the checkbox and populate my grid, but without a checkbox the grid displays as empty with no records. 
 
We have analyzed your query and we are able to understand that you have facing the issue for binding the data to the grid. We suspect that the reported issue may be occur because the data is not return in the correct format (i.e. if the checkbox selection is false then you have return the approvals directly without converting it to a list of object but when the checkbox is checked you have returned the approvals as list of object). 
 
So, please return the data as list of object. Refer the below solution, 
 
public IEnumerable GetApprovalDetails(bool hideComplete) 
    { 
        using (var connection = ConnectionService.CreateConnection()) 
        { 
            var approvals = connection.Query(GetApprovals, new { Entity = Entity.EntityID }); 
            if (hideComplete) 
            { 
                approvals = approvals.ToList(); 
            } 
            return approvals.ToList(); 
        } 
    } 
 
Still facing the issue, please get back to with below detail. 
 
  1. Share the video demonstration  of the issue.
 
Regards, 
Vignesh Natarajan. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon