Tuesday, March 20, 2012

Paging with Gridview and ObjectDataSource

I have a problem with efficiently paging with gridview and objectdatasoruce. I have GetPosts1(startRowIndex, maximumRow, topic_id) and GetPostsCount(topic_id). I tested each procedure and each are working correctly. The problem is with the controls. Here is the code for the controls.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames
DataSourceID="ObjectDataSource2">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="RowNumber" SortExpression="RowNumber" />
<asp:BoundField DataField="post_id" HeaderText="post_id" SortExpression="post_id" />
<asp:BoundField DataField="post_subject" HeaderText="post_subject" SortExpression="post_subject" />
<asp:BoundField DataField="post_text" HeaderText="post_text" SortExpression="post_text" />
<asp:BoundField DataField="post_time" HeaderText="post_time" SortExpression="post_time" />
<asp:BoundField DataField="topic_id" HeaderText="topic_id" SortExpression="topic_id" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}"
EnablePaging="True" SelectMethod="GetPosts1" SelectCountMethod="GetPostsCount" TypeName="PostsTableAdapters.discussions_GetPostsTableAdapter">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="48" Name="topic_id" QueryStringField="t" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

When I run the page, I get "A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll" and then "The thread '<No Name>' (0xbe0) has exited with code 0 (0x0)."

Could the problem be with null or empty values in the returned data?

Here is an example which work:

<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>

No comments:

Post a Comment