I have had a terrible time with this and have yet to find a solution. I have a radgrid with expandable items. Everything is setup to do filtering and paging; and it kind of works. When I filter it works fine, but if I try to go to the second page of the filter, it does go to page 2, but the data resets to the original data set.
I've looked at all the tutorials I could find but no luck. Any help would be appreciated.
I've looked at all the tutorials I could find but no luck. Any help would be appreciated.
4 Answers, 1 is accepted
0
Hi Roger,
Can you please give us little more details about your scenario as RadGrid's declaration, the way RadGrid is bound? You may check if you are rebinding the RadGrid control on every postback for example as this may cause similar behavior. Please note that in order operation as filtering, sorting, paging and grouping to work codelessly you should use either a DataSource control or Advanced Data-binding approach.
Best wishes,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Can you please give us little more details about your scenario as RadGrid's declaration, the way RadGrid is bound? You may check if you are rebinding the RadGrid control on every postback for example as this may cause similar behavior. Please note that in order operation as filtering, sorting, paging and grouping to work codelessly you should use either a DataSource control or Advanced Data-binding approach.
Best wishes,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Roger
Top achievements
Rank 1
answered on 15 Sep 2008, 09:07 PM
I bind to 3 SqlDataSources. I am no expert on the aspx since I just inherited this code from a contracted developer. According to the advanced data-binding approach link you gave me:
"If MasterTableView.EnableViewState has been set to false, grid will bind each time the page loads"
Indeed mine was false (it wasn't set at all), but when I set it to true nothing changed.
I've also read that if EnableViewState = true then the expandable tables won't work properly. Is this true?
Here's my aspx:
<rad:RadGrid ID="userSearchGrid" runat="server"
DataSourceID="ModelByDescriptionDataSource"
AllowPaging = "True"
EnableAJAX ="True"
AllowFilteringByColumn ="True"
AllowSorting ="True"
GridLines = "Horizontal"
AutoGenerateColumns="False"
Width="948px" Skin ="Mac"
oninit="userSearchGrid_Init"
onitemcommand="userSearchGrid_ItemCommand"
CssClass ="RadGrid"
ClientSettings-EnablePostBackOnRowClick="true"
meta:resourcekey="userSearchGridResource1" >
<ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<PagerStyle Mode="NextPrevAndNumeric" />
<HeaderStyle HorizontalAlign ="Left" />
<MasterTableView DataKeyNames="ProductID" CssClass="RadGridTable" NoMasterRecordsText="No documents to display" AllowFilteringByColumn="True" >
<DetailTables>
<rad:GridTableView runat="server" DataSourceID="ProductPrice" Width ="100%" DataKeyNames="DealerPrice" AllowFilteringByColumn="False" >
<ParentTableRelation><rad:GridRelationFields DetailKeyField="ProductID" MasterKeyField="ProductID" /></ParentTableRelation>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<rad:GridBoundColumn HeaderText= "MSRP" DataField ="MSRP" SortExpression ="MSRP" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left">
</rad:GridBoundColumn>
<rad:GridBoundColumn HeaderText= "Dealer Price" DataField ="DealerPrice" SortExpression ="DealerPrice" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left">
</rad:GridBoundColumn>
<rad:GridBoundColumn HeaderText= "Discounted Price" DataField ="DiscountedPrice" SortExpression ="DiscountedPrice" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="CurrencyName" SortExpression="Name" HeaderText ="Currency"
ShowSortIcon="False" UniqueName="Name">
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
</Columns>
</rad:GridTableView>
<rad:GridTableView runat="server" AllowFilteringByColumn="False" meta:resourcekey="GridTableViewResource1"
DataKeyNames="DocumentID" DataSourceID="ModelDocumentDataSource" Width="100%">
<ParentTableRelation>
<rad:GridRelationFields DetailKeyField="ProductID" MasterKeyField="ProductID" />
</ParentTableRelation>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<rad:GridBoundColumn DataField="DocumentID" DataType="System.Int16"
Display="False" HeaderText="DocumentID" ReadOnly="True"
SortExpression="DocumentID" UniqueName="DocumentID">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Name" Display="False"
HeaderText="Name of Document" SortExpression="Name" UniqueName="Name">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="FileName" Display="False"
HeaderText="File Name" SortExpression="FileName" UniqueName="FileName">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="DocumentType" HeaderText="Type Of Document"
SortExpression="DocumentType" UniqueName="DocumentType">
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="FilePath" Display="False" HeaderText="FilePath"
SortExpression="FilePath" UniqueName="FilePath">
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridTemplateColumn HeaderText="Click link to view document"
ShowSortIcon="False" UniqueName="TemplateColumn">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "ftp://pelco.com" + "/" + DataBinder.Eval(Container, "DataItem.FilePath") + "/" + DataBinder.Eval(Container, "DataItem.FileName")%>'
Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem,"Name","{0}" ) %>'>
</asp:HyperLink>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</rad:GridTemplateColumn>
</Columns>
</rad:GridTableView>
</DetailTables>
<rowindicatorcolumn visible="False"><HeaderStyle Width="20px" /></rowindicatorcolumn>
<ExpandCollapseColumn Resizable="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<rad:GridButtonColumn CommandName="Select" HeaderText="Add Model?" Text="Click here to add this model to order" UniqueName="column" ItemStyle-HorizontalAlign ="Left" meta:resourcekey="GridButtonColumnResource1">
<ItemStyle HorizontalAlign="Left" />
</rad:GridButtonColumn>
<rad:GridBoundColumn AutoPostBackOnFilter="false" DataField="ItemNumber" HeaderText="Model" SortExpression="ItemNumber" UniqueName="ItemNumber" FilterImageToolTip="Click here to filter by models" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left" >
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description" FilterImageToolTip="Click here to filter by description" ItemStyle-HorizontalAlign ="Left" AutoPostBackOnFilter ="true" >
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="ProductID" DataType="System.Int16" Display="False" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" UniqueName="ProductID"></rad:GridBoundColumn>
</Columns>
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
</MasterTableView>
<HierarchySettings CollapseTooltip="Click v to collapse this grid level" ExpandTooltip="Click > to expand this grid level" />
<SortingSettings SortedAscToolTip="Sorted by ascending order" SortedDescToolTip="Sorted by descending order"
SortToolTip="Click here to sort by this column" />
</rad:RadGrid>
<br/>
<asp:SqlDataSource ID="ProductPrice" runat="server"
ConnectionString="<%$ ConnectionStrings:BOSSConnectionString %>"
SelectCommand="usp_Product_Price_By_GroupID_RegionID_Select"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="ProductID" Type="Int16" />
<asp:SessionParameter Name="GroupID" SessionField="GroupId"
Type="Int32" />
<asp:SessionParameter Name="RegionID" SessionField="RegionId"
Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="ModelByDescriptionDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:BOSSConnectionString %>"
SelectCommand="usp_Product_By_Description_Select"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="a" Name="Description" Type="String" />
<asp:SessionParameter Name="RegionID" SessionField="RegionId"
Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="ModelDocumentDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:BOSSConnectionString %>"
SelectCommand="usp_Document_By_ProductID_Select"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="ProductID" Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>
<!------------------------------------------------------>
Here's my C#:
protected void userSearchGrid_Init(object sender, EventArgs e)
{
GridFilterMenu menu = userSearchGrid.FilterMenu;
int i = 0;
while (i < menu.Items.Count)
{
if (menu.Items[i].Text == "NoFilter" || menu.Items[i].Text == "Contains" || menu.Items[i].Text == "StartsWith" || menu.Items[i].Text == "EndsWith")
{
i++;
}
else
{
menu.Items.RemoveAt(i);
}
}
}
protected void userSearchGrid_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "Select")
{
GridItem item = (GridItem)e.Item;
GridDataItem dataItem = (GridDataItem)e.Item;
productIDFromProductFinder = Convert.ToInt32(dataItem["ProductID"].Text);
Session["PageID"] = PageNumbers.ProductSearch;
if (currentOrder1 == 0)
{
string query = "?PID=" + productIDFromProductFinder;
Response.Redirect("OrderType.aspx" + query);
}
else
{
string query = "?PID=" + productIDFromProductFinder;
Response.Redirect("OrderQuantitySelection.aspx" + query);
}
}
else if (e.CommandName == "RowClick")
{
e.Item.Expanded = !e.Item.Expanded;
}
else if (e.CommandName == "Filter")
{
string s = e.CommandArgument.ToString();
userSearchGrid.MasterTableView.CurrentPageIndex = 0;
}
else if (e.CommandName == "Page")
{
}
}
}
"If MasterTableView.EnableViewState has been set to false, grid will bind each time the page loads"
Indeed mine was false (it wasn't set at all), but when I set it to true nothing changed.
I've also read that if EnableViewState = true then the expandable tables won't work properly. Is this true?
Here's my aspx:
<rad:RadGrid ID="userSearchGrid" runat="server"
DataSourceID="ModelByDescriptionDataSource"
AllowPaging = "True"
EnableAJAX ="True"
AllowFilteringByColumn ="True"
AllowSorting ="True"
GridLines = "Horizontal"
AutoGenerateColumns="False"
Width="948px" Skin ="Mac"
oninit="userSearchGrid_Init"
onitemcommand="userSearchGrid_ItemCommand"
CssClass ="RadGrid"
ClientSettings-EnablePostBackOnRowClick="true"
meta:resourcekey="userSearchGridResource1" >
<ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<PagerStyle Mode="NextPrevAndNumeric" />
<HeaderStyle HorizontalAlign ="Left" />
<MasterTableView DataKeyNames="ProductID" CssClass="RadGridTable" NoMasterRecordsText="No documents to display" AllowFilteringByColumn="True" >
<DetailTables>
<rad:GridTableView runat="server" DataSourceID="ProductPrice" Width ="100%" DataKeyNames="DealerPrice" AllowFilteringByColumn="False" >
<ParentTableRelation><rad:GridRelationFields DetailKeyField="ProductID" MasterKeyField="ProductID" /></ParentTableRelation>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<rad:GridBoundColumn HeaderText= "MSRP" DataField ="MSRP" SortExpression ="MSRP" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left">
</rad:GridBoundColumn>
<rad:GridBoundColumn HeaderText= "Dealer Price" DataField ="DealerPrice" SortExpression ="DealerPrice" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left">
</rad:GridBoundColumn>
<rad:GridBoundColumn HeaderText= "Discounted Price" DataField ="DiscountedPrice" SortExpression ="DiscountedPrice" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="CurrencyName" SortExpression="Name" HeaderText ="Currency"
ShowSortIcon="False" UniqueName="Name">
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
</Columns>
</rad:GridTableView>
<rad:GridTableView runat="server" AllowFilteringByColumn="False" meta:resourcekey="GridTableViewResource1"
DataKeyNames="DocumentID" DataSourceID="ModelDocumentDataSource" Width="100%">
<ParentTableRelation>
<rad:GridRelationFields DetailKeyField="ProductID" MasterKeyField="ProductID" />
</ParentTableRelation>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<rad:GridBoundColumn DataField="DocumentID" DataType="System.Int16"
Display="False" HeaderText="DocumentID" ReadOnly="True"
SortExpression="DocumentID" UniqueName="DocumentID">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Name" Display="False"
HeaderText="Name of Document" SortExpression="Name" UniqueName="Name">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="FileName" Display="False"
HeaderText="File Name" SortExpression="FileName" UniqueName="FileName">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="DocumentType" HeaderText="Type Of Document"
SortExpression="DocumentType" UniqueName="DocumentType">
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="FilePath" Display="False" HeaderText="FilePath"
SortExpression="FilePath" UniqueName="FilePath">
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridTemplateColumn HeaderText="Click link to view document"
ShowSortIcon="False" UniqueName="TemplateColumn">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "ftp://pelco.com" + "/" + DataBinder.Eval(Container, "DataItem.FilePath") + "/" + DataBinder.Eval(Container, "DataItem.FileName")%>'
Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem,"Name","{0}" ) %>'>
</asp:HyperLink>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" />
</rad:GridTemplateColumn>
</Columns>
</rad:GridTableView>
</DetailTables>
<rowindicatorcolumn visible="False"><HeaderStyle Width="20px" /></rowindicatorcolumn>
<ExpandCollapseColumn Resizable="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<rad:GridButtonColumn CommandName="Select" HeaderText="Add Model?" Text="Click here to add this model to order" UniqueName="column" ItemStyle-HorizontalAlign ="Left" meta:resourcekey="GridButtonColumnResource1">
<ItemStyle HorizontalAlign="Left" />
</rad:GridButtonColumn>
<rad:GridBoundColumn AutoPostBackOnFilter="false" DataField="ItemNumber" HeaderText="Model" SortExpression="ItemNumber" UniqueName="ItemNumber" FilterImageToolTip="Click here to filter by models" ShowSortIcon="false" ItemStyle-HorizontalAlign ="Left" >
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description" FilterImageToolTip="Click here to filter by description" ItemStyle-HorizontalAlign ="Left" AutoPostBackOnFilter ="true" >
<ItemStyle HorizontalAlign="Left" />
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="ProductID" DataType="System.Int16" Display="False" HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" UniqueName="ProductID"></rad:GridBoundColumn>
</Columns>
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
</MasterTableView>
<HierarchySettings CollapseTooltip="Click v to collapse this grid level" ExpandTooltip="Click > to expand this grid level" />
<SortingSettings SortedAscToolTip="Sorted by ascending order" SortedDescToolTip="Sorted by descending order"
SortToolTip="Click here to sort by this column" />
</rad:RadGrid>
<br/>
<asp:SqlDataSource ID="ProductPrice" runat="server"
ConnectionString="<%$ ConnectionStrings:BOSSConnectionString %>"
SelectCommand="usp_Product_Price_By_GroupID_RegionID_Select"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="ProductID" Type="Int16" />
<asp:SessionParameter Name="GroupID" SessionField="GroupId"
Type="Int32" />
<asp:SessionParameter Name="RegionID" SessionField="RegionId"
Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="ModelByDescriptionDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:BOSSConnectionString %>"
SelectCommand="usp_Product_By_Description_Select"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="a" Name="Description" Type="String" />
<asp:SessionParameter Name="RegionID" SessionField="RegionId"
Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="ModelDocumentDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:BOSSConnectionString %>"
SelectCommand="usp_Document_By_ProductID_Select"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="ProductID" Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>
<!------------------------------------------------------>
Here's my C#:
protected void userSearchGrid_Init(object sender, EventArgs e)
{
GridFilterMenu menu = userSearchGrid.FilterMenu;
int i = 0;
while (i < menu.Items.Count)
{
if (menu.Items[i].Text == "NoFilter" || menu.Items[i].Text == "Contains" || menu.Items[i].Text == "StartsWith" || menu.Items[i].Text == "EndsWith")
{
i++;
}
else
{
menu.Items.RemoveAt(i);
}
}
}
protected void userSearchGrid_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "Select")
{
GridItem item = (GridItem)e.Item;
GridDataItem dataItem = (GridDataItem)e.Item;
productIDFromProductFinder = Convert.ToInt32(dataItem["ProductID"].Text);
Session["PageID"] = PageNumbers.ProductSearch;
if (currentOrder1 == 0)
{
string query = "?PID=" + productIDFromProductFinder;
Response.Redirect("OrderType.aspx" + query);
}
else
{
string query = "?PID=" + productIDFromProductFinder;
Response.Redirect("OrderQuantitySelection.aspx" + query);
}
}
else if (e.CommandName == "RowClick")
{
e.Item.Expanded = !e.Item.Expanded;
}
else if (e.CommandName == "Filter")
{
string s = e.CommandArgument.ToString();
userSearchGrid.MasterTableView.CurrentPageIndex = 0;
}
else if (e.CommandName == "Page")
{
}
}
}
0
Hello Roger,
Unfortunately I'm unable to reproduce the described behavior on my local machine. I suspect that the cause may be due to session parameters as they tend to have strange behavior for time to time. If you please can send us (attached to a formal ticket) a small runnable project I'll be more that happy to debug it and provide you with more to-the-point answer.
Sincerely yours,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Unfortunately I'm unable to reproduce the described behavior on my local machine. I suspect that the cause may be due to session parameters as they tend to have strange behavior for time to time. If you please can send us (attached to a formal ticket) a small runnable project I'll be more that happy to debug it and provide you with more to-the-point answer.
Sincerely yours,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Roger
Top achievements
Rank 1
answered on 16 Sep 2008, 04:49 PM
OK I found the error and this is a strange one (to me at least). I have many of my page's values stored in a corresponding resx file for future localization purposes. In the resx file, if I remove the row named:
userSearchGridResource1.MasterTableView.FilterExpression, and this row's value was left blank,
where meta:resourcekey="userSearchGridResource1" for my RadGrid,
then the ajax works properly. I don't know if that is considered a bug or not, but it is pretty odd to me.
userSearchGridResource1.MasterTableView.FilterExpression, and this row's value was left blank,
where meta:resourcekey="userSearchGridResource1" for my RadGrid,
then the ajax works properly. I don't know if that is considered a bug or not, but it is pretty odd to me.