Harlem 98

Harlem 98

  • NA
  • 161
  • 18.6k

Load data into grid

Oct 19 2021 3:18 PM

I'm having huge problems loading data into a grid. i've encountered a number of problems, which i´ve been solving through different approachs, and now i dont have any exception, but i still cant load the data into the grid.

The data is filtered according to "rdpInvestigador" external selectedValue, and should load in the grid accordingly.

I use a n-layer architecture and ASP ObjectDataSource to Bind DB.

I will put the main parts of the code, in order to be possible to understand and find the issue. I will also attach an image with the appearence of the system, and a sample code containing a more complete file, but still imcomplete because i'm working on a larger application that i cant replicate on my machine.

I believe the problem is on CS code, but it could also be on the BLL "GetList" method. Can you identify where the problem is?

// HTML

<script type="text/javascript">
  function refreshGrid(arg) {
  var radManager = $find('<%= 
  RadAjaxManager.GetCurrent(Page).ClientID %>');
  if (!arg) {
   radManager.ajaxRequest("Rebind");
  }
    else {
   radManager.ajaxRequest(arg);
            }
   }

function myUserControlClickHandler() {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("FromUserControl");                       }
 </script>

<telerik:RadComboBox ID="rdpInvestigador" </telerik:RadComboBox>

<telerik:RadButton ID="ButtonPerformSearch" Text="Aceder à listagem de timesheets" ValidationGroup="search" OnClick="ButtonPerformSearch_Click"
                    runat="server"  CssClass="btn btn-mini"  Width="50%" ButtonType="ToggleButton"
                   CausesValidation="true"></telerik:RadButton>
 <asp:LinkButton ID="lkbPesquisar" runat="server" CssClass="btn btn-mini" OnClick="lkbPesquisar_Click">pesquisar</asp:LinkButton>
   
<telerik:RadGrid ID="gvTimesheets" DataSourceID="DataSourceTimesheets" OnSelectedIndexChanged="rdpInvestigador_SelectedIndexChanged" OnItemCommand="gvTimesheets_ItemCommand"

<asp:ObjectDataSource ID="DataSourceTimesheets" runat="server" EnablePaging="True" OnSelecting="DataSourceTimesheets_Selecting" SortParameterName="sortType" TypeName="UMinho.GestaoProjectos.BLL.BLLListagemTimesheets" 
                   SelectMethod="GetList" SelectCountMethod="GetListCount">
               
                    <SelectParameters>

                         <asp:ControlParameter ControlID="rdpInvestigador" Name="IDRecursoHumano" PropertyName="SelectedValue" DefaultValue="" Type="Int32" />
                         <asp:Parameter  Name="ID"  Type="Int32" />
                        <asp:Parameter  Name="DataEnvio"  Type="datetime"  />
                         <asp:Parameter  Name="IDEstadoTimesheet"  Type="Int32" />                       
                         <asp:Parameter  Name="AssinaturaTimesheet"  Type="string" />       
                          <asp:Parameter  Name="Observações"  Type="string" />
                          <asp:Parameter  Name="Ficheiro"  Type="string" />
                          <asp:Parameter  Name="FileTipo"  Type="string" />
                         <asp:Parameter  Name="FileContent" Type="Byte"   />
                        <asp:Parameter Name="login" Type="String" />
                    </SelectParameters>
                </asp:ObjectDataSource>
        
        
        
        
        
        
        
           

ASP.NET (C#)
//BLL method, used in object data source (wanted data that not load is "listagem timesheet"

public List GetList(int? ID, int? IDRecursoHumano, DateTime? DataEnvio, string AssinaturaTimesheet,int? IDEstadoTimesheet, string Observações, string Ficheiro, string FileTipo, byte FileContent, string sortType, int maximumRows, int startRowIndex, string login)
{
    using (GestaoProjectosEntities db = new GestaoProjectosEntities())
    {
        var entities = from e in db.ListagemTimesheets
                         select e;        entities = GetQueryList(entities, ID, IDRecursoHumano, DataEnvio, AssinaturaTimesheet, IDEstadoTimesheet, Observações, Ficheiro, FileTipo, FileContent, login);
        entities = GetListSort(entities.AsQueryable(), sortType);
        entities.Skip(startRowIndex).Take(maximumRows);
        return entities.ToList();
    }
}public int GetListCount(int? ID, int? IDRecursoHumano, DateTime? DataEnvio, string AssinaturaTimesheet,int? IDEstadoTimesheet, string Observações, string Ficheiro, string FileTipo, byte FileContent, string login)
{
    using (GestaoProjectosEntities db = new GestaoProjectosEntities())
    {
        var entities = from e in db.ListagemTimesheets
                       select e;
        return GetQueryList(entities, ID, IDRecursoHumano, DataEnvio, AssinaturaTimesheet, IDEstadoTimesheet, Observações, Ficheiro, FileTipo, FileContent, login).Count();
    }
}

C#
// Cs class, with 3 approachs: 1-FormsMode; 2-OnSelectedIndex(); 3-DataBind()

public Utils.FormMode FormMode
    {
        get { return ViewState["___formmode"] == null ? Utils.FormMode.CreateMode : (Utils.FormMode)ViewState["___formmode"]; }

        set { ViewState["___formmode"] = value; }
    }
    //ID
    public int ID
    {
        get { return ViewState["___entitypk"] == null ? 0 : (int)ViewState["___entitypk"]; }

        set { ViewState["___entitypk"] = value; }
    }

    BLLListagemTimesheets listagembll = new BLLListagemTimesheets();


    protected void Page_Load(object sender, EventArgs e)
    {
        //Get reference to AjaxManager (from Master) 
        var manager = RadAjaxManager.GetCurrent(Page);

        //Create a new delegate to handle the AjaxRequest event 
        //manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(RadAjaxManager1_AjaxRequest);

        //Add your ajax settings programmatically (with ref to Master manager) 
        manager.AjaxSettings.AddAjaxSetting(manager, gvTimesheets);

        if (Request.QueryString["ID"] != null)
        {
            if (Request.QueryString["action"] != "TemplateFileDownload")
                DownloadFile(Convert.ToInt32(Request.QueryString["ID"]));
            else
                ExportFile_Click();
        }

        else
        {
            if (!Page.IsPostBack)
            {
                RecursoHumano rh = new RecursoHumano();

                rdpUnidade.DataValueField = "ID";
                rdpUnidade.DataTextField = "NomeUnidade";
                rdpUnidade.DataSource = new BLLUnidades().GetAllCentrosInvestigacao();
                rdpUnidade.DataBind();
                //rdpUnidade.ClearSelection();

                // Sem filtros (Nao consigo utilizar o AjaxManager!) // new BLLProjectoEquipa().GetAll()
                rdpInvestigador.DataSource = new BLLRecursoHumano().GetAll();
                rdpInvestigador.DataValueField = "ID";
                rdpInvestigador.DataTextField = "Nome";
                rdpInvestigador.DataBind();
                rdpInvestigador.Items.Insert(0, new RadComboBoxItem("", ""));


            }
        }
      //2 approaches, 1st one

      protected void ButtonPerformSearch_Click(object sender, EventArgs e)
    {
        gvTimesheets.Rebind();
    }

    protected void rdpInvestigador_SelectedIndexChanged(object sender, EventArgs e)
    {
        gvTimesheets.DataSource = rdpInvestigador.SelectedValue;
        gvTimesheets.Rebind();
    }  
      //Second

     protected void lkbPesquisar_Click(object sender, EventArgs e)
    {
        BindInvestigadores();
    }

     private void BindInvestigadores() // gvTimesheets.DataBind(); nao dá exception mas nao carrega
    {
  
        gvTimesheets.DataBind();
    }

 


Attachment: Sample_(2).zip

Answers (8)