Showing posts with label effecinty. Show all posts
Showing posts with label effecinty. Show all posts

Monday, March 12, 2012

Paging with Gridview and ObjectDataSource

I'm trying to effecinty page through many rows of data with the gridview and objectdatasource. I'm having trouble. I'm using a table adapter with predefined counting and select methods. I have tested all the methods and they all work properly. But when I configure the object datasource to use the table adapter, and set the gridviews datasrouce, the page doesn't load and I wind up getting "time out". Any help?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="objTopics">
<Columns>
<asp:BoundField DataField="topic_title" />
</Columns>
<EmptyDataTemplate>
<p>NOTHING HERE</p>
</EmptyDataTemplate>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetTopics" SelectCountMethod="GetTopicsRowCount" TypeName="TopicsTableAdapters.discussions_GetTopicsSubSetTableAdapter">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="startRowIndex" Type="Int32" />
<asp:Parameter DefaultValue="10" Name="maximumRows" Type="Int32" />
<asp:Parameter DefaultValue="1" Name="board_id" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

<asp:GridViewID="gvResult"

runat="server"AutoGenerateColumns="False"CssClass="dataGrid"

OnSelectedIndexChanged="GridView1_SelectedIndexChanged"OnRowDataBound="gvResult_RowDataBound"AllowPaging="True"AllowSorting="True"DataSourceID="odsObjectDataSource"OnPageIndexChanged="gvResult_PageIndexChanged"PageSize="5">

<Columns>

<asp:ButtonFieldCommandName="Select"HeaderText="Select"Text="<img src='../IMAGES/select.jpg'/>"/>

<asp:BoundFieldDataField="SocieteId"HeaderText="Identifiant"ReadOnly="True"/>

<asp:BoundFieldDataField="SocieteLocalite"HeaderText="Localité"ReadOnly="True"/>

</Columns>

<AlternatingRowStyleCssClass="alt"/>

<PagerSettingsMode="NextPreviousFirstLast"/>

</asp:GridView>

<asp:LabelID="lblError"runat="server"Text=""></asp:Label></div>

<asp:ObjectDataSourceID="odsObjectDataSource"runat="server"SelectMethod="GetResults"TypeName="ResultsList">

<SelectParameters>

<asp:ParameterDefaultValue="0"Name="StartRow"Type="Int32"/>

<asp:SessionParameterName="xslSearch"SessionField="xsltPathShowRezults"Type="String"/>

</SelectParameters>

</asp:ObjectDataSource>

For the object datasource you have to writye a class wich will get data, like

privateDataView GetData(int StartRow,string xslSearch)

{

//your code here

return PagedResultsTable.DefaultView;

}

and this method is set in the design for the object datasource.