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

Grid goes Empty on PostBack

1 Answer 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 04 Jul 2011, 09:34 AM
Hi,

Im having some trouble with a simple Grid bound declaratively to an ObjectDataSource, on first PageLoad it works fine but after PostBack (sorting for example) the Grid goes empty as if it loses the DataSource. For testing purposes i also tried an asp:GridView and that works perfectly fine. Any Ideas on what could be the Problem?
The SelectMethod on the ObjectDataSource returns an DataSet.

<telerik:RadGrid
    ID="rgData"
    runat="server"
    AllowSorting="true"
    Skin="<%$Appsettings:TelerikSkin %>"   
    ClientSettings-AllowColumnsReorder="true"
    ClientSettings-Resizing-AllowColumnResize="true"
    DataSourceID="odsGrid"
    Width="400px"
    AutoGenerateColumns="false">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn
                HeaderText="AttributeName"
                SortExpression="AttributeName"
                DataField="AttributeName">
            </telerik:GridBoundColumn>               
            <telerik:GridBoundColumn
                HeaderText="DataValue"
                SortExpression="DataValue"
                DataField="DataValue">
            </telerik:GridBoundColumn>               
        </Columns>
    </MasterTableView>               
</telerik:RadGrid>
 
<asp:GridView
    ID="gData"
    runat="server"
    AllowSorting="true"
    DataSourceID="odsGrid"
    Width="400px"
    AutoGenerateColumns="false">
    <Columns>   
        <asp:BoundField
                HeaderText="AttributeName"
                SortExpression="AttributeName"
                DataField="AttributeName">       
        </asp:BoundField>               
        <asp:BoundField
                HeaderText="DataValue"
                SortExpression="DataValue"
                DataField="DataValue">
        </asp:BoundField>
    </Columns>   
</asp:GridView>
 
<asp:ObjectDataSource
    ID="odsGrid"
    SelectMethod="GetGridData"
    TypeName="dataViewGridInterface"     
    runat="server"></asp:ObjectDataSource>

Regards,
Alex

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Jul 2011, 09:55 AM
Hello Alex,

In order to implement advance features like paging/sorting you should use advanced data binding using the NeedDataSource event. Check the following help documentation which explains more about this.
Advanced Data-binding (using NeedDataSource event).

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