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

sorting grid looses data in grid

3 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 03 Apr 2013, 03:12 PM
Hi,
we are using 2013 Q1 Radgrid.

I came to know that Radgrid doesn't have clientside sorting unless it is done through webservice call etc. Only other option is to enable sorting on server side. In sort command event, help link suggest to rebind the grid. My situation is like this:

I bind the grid in page load event when it is not a postback like this:

protected

 

void Page_Load(....)

 

 

    if (!IsPostBack)

 

    {

 

        //bind radgrid
        bindgrid(txtbox1.text, dropdownlist1.selectedvalue);
     }
}

private void bindgrid(string txtvalue, string ddlvalue)
{
      radgrid1.DataSource = customobject;   //data retrieved as custom object from databased using those parameters
      radgrid1.DataBind();
}

Based on certain conditions some columns are shown/hide in ItemDataBound event. On the page, there are many other controls along with Radgrid. User can select different choices of these controls (like different data, different list item from dropdown etc) and click on another button called refresh. In this button click event we are binding grid again with different parameter values.

We have a button called 'ShowStatus'. When this button is clicked, status column (which is hidden initially) should be shown. we loop thru all the rows and get key values (as xml) and send to database and get back status for each item as xml. Then again we loop thru rows and assign status to each row status cell.
This is working fine and when 'ShowStatus' button is clicked, status column is showing up with data.

 

protected

 

void btnShowStatus_Click(object sender, EventArgs e)

    // setting status column to be displayed
    // loop thru grid items and set status column to appropriate status coming from database as xml.

 

}

The problem is after this, if user clicks on one of the columns to sort, I am not sure what to do in sort command event. According to help, I need to bind the grid again. If I call bindgrid routine, I lose how it was before. I need the grid to display as it was before (before postback) with sorted data. How can I restore grid.


I appreciate your response.
Thanks,
Prathiba.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Apr 2013, 08:05 AM
Hi,

RadGrid fires the NeedDataSource event each time it needs to be bound to a data source. Mae sure that grid uses advanced data binding using its NeedDataSource event.

Thanks,
Princy
0
Prathibarani
Top achievements
Rank 1
answered on 04 Apr 2013, 02:03 PM
Thank you for the response. Yes. NeedDataSource event will rebind the grid. But if you read my post, I did some columns visible in some other button click event (btnShowStatus_Click event - which made status column visible and populated data). If we rebind the grid in NeedDataSource event, we will loose that data in status column and status column is not visible. I want grid to be restored as it was before sorting which makes it to postback. Rebind() makes it to call NeedDataSource event in which we bind grid just as it was done for the first time.

Thanks,
Prathiba
0
Kostadin
Telerik team
answered on 08 Apr 2013, 10:34 AM
Hello Prathiba,

I agree with Princy to use advanced data binding instead simple data binding. Note that you could pass a different parameters in order to bind to different data sources. Additionally I would suggest you to populate the status column with data and only hide it on button click.

Kind regards,
Kostadin
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prathibarani
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or