I have a page with a GridView bound to a custom ObjectDataSource. Grid has a selection ability which triggers FormView to retrieve selected index and use it as a parameter for a SELECT to get details about specific item. The problem is when I select a row in that grid on a page where there are less items than PageSize (Paging is enabled, DataSource is a List) the last item just dissapears and selection is made properly. When I select an item from grid page that has as many items as PageSize nothing dissapears at all. Any help?
My code is nothing out of ordinary. Here's the ObjectDataSource and a GridView (layout ommited):
<asp:ObjectDataSource ID="gridSource" runat="server" EnablePaging="true" TypeName="film.DBComm"
SelectMethod="GetPage" SelectCountMethod="GetCount" />
<asp:ObjectDataSource ID="detailSource" runat="server" TypeName="film.DBComm"
SelectMethod="GetDetails">
<SelectParameters>
<asp:ControlParameter ControlID="ResultGrid" Name="ID" PropertyName="SelectedDataKey.Values["ID"]" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="ResultGrid" runat="server" DataSourceID="gridSource" DataKeyNames="ID"
AllowPaging="True" PageSize="20" AutoGenerateColumns="False" BorderStyle="None"
GridLines="None" EnableSortingAndPagingCallbacks="false" Font-Size="Small" Width="90%"
CssClass="gridMargins">
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="<< Pierwsza" LastPageText="Ostatnia >>"
NextPageText="Następna" PreviousPageText="Poprzednia" Position="Top" />
<PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" ForeColor="Orange" BackColor="#F0FFF0"
Font-Size="Small" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="Number" SortExpression="ID" Visible="false" />
<asp:BoundField DataField="TitleColumn" HeaderText="Title" SortExpression="TitleColumn"
ItemStyle-Width="40%" HeaderStyle-Width="40%">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemStyle Width="40%"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="OriginalTitleColumn" HeaderText="Original title" SortExpression="OriginalTitleColumn"
ItemStyle-Width="35%" HeaderStyle-Width="35%">
<HeaderStyle Width="35%"></HeaderStyle>
<ItemStyle Width="35%"></ItemStyle>
</asp:BoundField>
<asp:CommandField ButtonType="Image" CancelText="Cancel" SelectImageUrl="~/Images/order.gif"
SelectText="Order" ShowSelectButton="True" ItemStyle-Width="5%" HeaderStyle-Width="5%">
<HeaderStyle Width="5%"></HeaderStyle>
<ItemStyle Width="5%"></ItemStyle>
</asp:CommandField>
</Columns>
</asp:GridView>
<asp:FormView ID="Details" runat="server" DataSourceID="detailSource">
<ItemTemplate>
<b>
<label>
Number
</label>
<%# Eval("ID") %>
...other fields...
<asp:LinkButton ID="Order" runat="server" CommandName="Order" CommandArgument="<%# Eval("ID") %>"
Text="Order" />
</ItemTemplate>
</asp:FormView>
And the method that calls a stored procedure from a database and gets a results page:
public DataTable GetPage(int startRowIndex, int maximumRows)
{
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("GetViewPage", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Start", startRowIndex);
cmd.Parameters.AddWithValue("@Count", maximumRows);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
adapter.Fill(ds);
return ds.Tables[0];
}
catch (SqlException)
{
throw new ApplicationException("Data read error. Try again later.");
}
}