0

The RadGrid is generated from the server-side with template fields. NeedDataSource() is what is used for data binding. On every postback, RadGrid loses the values as the NeedDataSource is not called.Manually doing a Rebind() on the Onload() does not help either.

The Grid Structure is defined in OnLoad() and executed once on !IsPostback()

I remember reading somewhere that when building the Grid structure dynamically from the serverside, the grid 'needs' to be Rebind() on every postback.

Does RadGrid not maintain the values on postback? Is this something to do with ViewState?

3 Answers 3

2

The "NeedDataSource" event should occur on postbacks as well. You could try setting up your page using an RadAjaxManager I suppose. Does your grid load data on the first load? Try following the demo pages they have set up on the grids, as its one of the best examples of the different ways to set them up.

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/simplebinding/defaultcs.aspx

2
  • Data in the grid loads on first load. It is only the subsequent postbacks, I lose the data. The NeedDataSource event does not occur on every postback. Is using the RadAjaxManger the only option? Aug 5, 2011 at 19:24
  • Yeah I think so. I'll be the first to admit I don't know every inner working of the RadGrid because even if I did it would still surprise me. I recommend trying the RadAjaxManager. In either case, let me know what you find out.
    – Xiphos
    Aug 5, 2011 at 22:22
1

As per radgrid documentation if you create the grid programmatically you need to create it in OnInit method: http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html (Creating a RadGrid on Page_Init section) The onLoad can be used when the grid is partially added into the markup. Hope this helps.

0

create function to bind data to Radgrid

private void BindData()
    {
    //Get data from database
        //DBData can be datatable or list
        RadGrid1.DataSource = DBData;
    }

then call in page load event

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        catch (Exception ex)
        {

        }
    }

then you can use same function in NeedDataSource event

    protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        BindCommentData();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.