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
pesquisar
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();
}
Harlem 98Posted Oct 20, 2021, 4:29 PM
Srinivasan RamamoorthiPosted Oct 20, 2021, 3:53 PM
Harlem 98Posted Oct 20, 2021, 3:49 PM
Srinivasan RamamoorthiPosted Oct 20, 2021, 3:34 PM
Harlem 98Posted Oct 20, 2021, 3:30 PM
Srinivasan RamamoorthiPosted Oct 20, 2021, 2:58 PM
Harlem 98Posted Oct 20, 2021, 2:33 PM
Hello @Srinivasan. I try to implement your suggestion with any results. Should be this structure?
Srinivasan RamamoorthiPosted Oct 20, 2021, 11:37 AM
In your code, the radgrid gvTimesheets is not set to datasource, it is set to selected value. You have to change that to
gvTimesheets.datasource = //call the method to get the dataset, filter the dataset based on the combo value selected
then rebind
gvtimesheets.rebind();
You have to place this code in combobox selectindexhanged event and searchbutton click event.