Load data into grid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harlem98
    New Member
    • Oct 2021
    • 3

    Load data into grid

    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 "rdpInvestigado r" external selectedValue, and should load in the grid accordingly.

    I use a n-layer architecture and ASP ObjectDataSourc e 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

    Code:
    <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>
    //BLL method, used in object data source (wanted data that not load is "listagem timesheet"

    Code:
     public List<ListagemTimesheet> 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();
                 }
             }
    // Cs class, with 3 approachs: 1-FormsMode; 2-OnSelectedIndex (); 3-DataBind()

    Code:
    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();
        BLLPesquisarTimesheet pesquisarbll = new BLLPesquisarTimesheet();
        BLLTemplateFile templatebll = new BLLTemplateFile();
    
        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();
        }
    After many tries, cant get any ideia of the problem
Working...