Hi everyone,
I got a problem, finally after all other problem i had get my grid and code to somehow support paging from custom store procedure. Now it looks that grid works with paging but after i do any postback it breaks Actually, it looks that it doesn't connect or fetch data - it is empty. Now my GridView1_SelectedIndexChanged fires, but GridView1.DataKeys.Count is 0? After i change pageindex it is also empty?
could anyone help?
Vjeran
Custom method - works:
public override TList<Cmstabs> GetByCategoryGroupPaged(TransactionManager transactionManager, int start, int pageLength , System.Int32? categoryId, System.Int32? groupId, System.Int32? pageIndex, System.Int32? pageSize, ref System.Int32? totalRowCount)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = database.GetStoredProcCommand("dbo.cust_cmstabs_GetByCategoryGroupPaged");
database.AddInParameter(commandWrapper, "@CategoryId", DbType.Int32, categoryId );
database.AddInParameter(commandWrapper, "@GroupId", DbType.Int32, groupId );
database.AddInParameter(commandWrapper, "@PageIndex", DbType.Int32, pageIndex );
database.AddInParameter(commandWrapper, "@PageSize", DbType.Int32, pageSize );
database.AddParameter(commandWrapper, "@TotalRowCount", DbType.Int32, 4, ParameterDirection.InputOutput, true, 10, 0, string.Empty, DataRowVersion.Current, totalRowCount);
IDataReader reader = null;
//Create Collection
adriatica.Entities.TList<Cmstabs> rows = new adriatica.Entities.TList<Cmstabs>();
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "GetByCategoryGroupPaged", rows));
if (transactionManager != null)
{
reader = Utility.ExecuteReader(transactionManager, commandWrapper);
}
else
{
reader = Utility.ExecuteReader(database, commandWrapper);
}
try
{
Fill(reader, rows, start, pageLength);
}
finally
{
if (reader != null)
reader.Close();
}
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "GetByCategoryGroupPaged", rows));
totalRowCount = Utility.GetParameterValue<System.Int32?>(commandWrapper.Parameters["@TotalRowCount"]);
return rows;
}
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
DataSourceID="CmsTabsDataSource"
AllowPaging="true"
EnableSortingAndPagingCallbacks="false"
EmptyDataText="No records"
AllowSorting="false"
PageSize="10"
PageIndex="0"
DataKeyNames="Id">
<Columns>
<asp:CommandField ShowSelectButton="True" ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Redosljed" SortExpression="tabsorder" />
<asp:BoundField DataField="Name" HeaderText="Naziv" SortExpression="name" />
<data:HyperLinkField HeaderText="Tip stanice"
DataNavigateUrlFormatString="CmsTabtypesEdit.aspx?Id={0}"
DataNavigateUrlFields="Id" DataContainer="TabtypeSource" DataTextField="Name" />
<asp:BoundField DataField="Link" HeaderText="Link" SortExpression="link" />
</Columns>
</asp:GridView>
<br />
<asp:Button runat="server" ID="btnCmsTabs" OnClientClick="BLOCKED SCRIPTlocation.href='CmsTabsEdit.aspx'; return false;" Text="Add New"></asp:Button>
<data:CmsTabsDataSource ID="CmsTabsDataSource" runat="server"
SelectMethod="GetByCategoryGroupPaged"
EnablePaging="True"
EnableSorting="True"
EnableDeepLoad="True"
CustomMethodRecordCountParamName="TotalRowCount"
>
<DeepLoadProperties Method="IncludeChildren" Recursive="False">
<Types>
<data:CmsTabsProperty Name="CmsTabtypes" />
</Types>
</DeepLoadProperties>
<Parameters>
<asp:ControlParameter Name="CategoryId" ControlID="kategorije" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter Name="GroupId" ControlID="ddlgrupe" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />
<asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />
<data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
</Parameters>
</data:CmsTabsDataSource>