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

DataBinding from DetailTableBind event? (The grid thinks I am)

1 Answer 677 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 16 Apr 2013, 07:03 PM
Edit: I found that I was calling databind from the method I called from the NeedDataSource handler in some cases, including this one.  I would delete the post if I could.


Greetings, I'm having an issue where I get the error:

You should not call DataBind in NeedDataSource event handler. DataBind would take place automatically right after NeedDataSource handler finishes execution.

And I get this error when I expand a details view on a row in my Grid.  This is the Detail Table Data Bind handler:


protected void grdSearchResults_DetailTableDataBind(object sender, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
            GridDataItem dataItem = e.DetailTableView.ParentItem;
 
            int itemID = int.Parse(dataItem.GetDataKeyValue("Item_ID").ToString());
            IMyService dbItems = ServiceFactory.Create<MyService>();
            e.DetailTableView.DataSource = dbItems.GetItemsByID(itemID);
 
            uppnlSearchCriteria.Update();
        }

Note that the update panel is not where the grid is, but it is where the error
 label is, which is showing me that aforementioned error.

Based on the documentation and examples I've been looking at today, I'm doing 
things right by setting the datasource and NOT actually binding, but the Grid 
seems to think I'm calling databind.

Is there something I'm missing here or somewhere in the code I should look 
to see how this is happening?

Thanks,

Alex

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Apr 2013, 03:53 AM
Hi,

You should never call the Rebind() method or DataBind() as well when using advanced data-binding through NeedDataSource. You can populate the detailtable in DetailTable event by extracting the datakeyvalue. Hope this helps.

Thanks,
SHinu
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or