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

Make RadGrid DataBind after filter

3 Answers 108 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Caio
Top achievements
Rank 1
Caio asked on 30 Oct 2013, 06:39 PM
Hi, all!
I've an RadGrid.
After I make filter, no loads this RadGrid. Because my event CarregaGrid() this inside "If(!IsPostBack)".
I load this RadGrid with SQL, in List (DataSource in my .cs)
If I call CarregaGrid() outside if (!IsPostBack), I've an error.
When I load this RadGrid after an filter? Or... When I call CarregaGrid() outside If(!IsPostBack) without error?


public void CarregaGrid()
    {
        var listaRequest = new Locations().ConsultLocations();
        if (listaRequest != null)
        {
            this.RadGrid1.DataSource = listaRequest;
            this.RadGrid1.DataBind();
        }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["idioma"] == null)
            {
                string idioma = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToString();
                Idioma.MudaCultura(idioma);
                Session["idioma"] = idioma;
            }
 
            else if (Session["idioma"] != null)
            {
                string idioma = Session["idioma"].ToString();
                Idioma.MudaCultura(idioma);
            }
 
            IdiomaList.Items.Add("PORTUGUÊS");
            IdiomaList.Items.Add("ENGLISH");
            IdiomaList.Items.Add("ESPAÑOL");
 
            if (Session["idioma"].ToString() == "pt")
            {
                IdiomaList.SelectedValue = "PORTUGUÊS";
            }
 
            else if (Session["idioma"].ToString() == "en")
            {
                IdiomaList.SelectedValue = "ENGLISH";
            }
 
            else if (Session["idioma"].ToString() == "es")
            {
                IdiomaList.SelectedValue = "ESPAÑOL";
            }
 
            RadGrid1.Columns[1].HeaderText = Idioma.RetornaMensagem("location");
            RadGrid1.Columns[2].HeaderText = Idioma.RetornaMensagem("servername");
            CarregaGrid();
        }
    }

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Nov 2013, 12:07 PM
Hi Caio,

Please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

Hope this helps. Please make the suggested modification and let us know about the result.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Henry
Top achievements
Rank 1
answered on 29 Apr 2019, 01:29 PM
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName || e.CommandName == RadGrid.SortCommandName) //FilterCommandName is raised when filtering, SortCommandName is raised when sorting
            {
                CarregaGrid();
            }
}
0
Eyup
Telerik team
answered on 02 May 2019, 04:50 AM
Hi Henry,

Thanks for sharing your code with our community. You can use the NeedDataSource event handler and let the grid handle the rebinding action automatically:
https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-bind-radgrid-properly-on-server-side

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Filter
Asked by
Caio
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Henry
Top achievements
Rank 1
Share this question
or