This is a migrated thread and some comments may be shown as answers.

Lose the filter on edit or page navigation

5 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick Wassmer
Top achievements
Rank 1
Patrick Wassmer asked on 11 Dec 2008, 08:03 AM
Hi,
I have a big problem on my gridview.... I load my gridview with a dataset in the OnNeedDataSource event. All seems ok.. But, when i filter one of the columns, i lose then my selection when i try to edit a record or when i change the page of my grid... It seems the every postback event makes lose every filter parameters.

Any idea ?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Dec 2008, 11:59 AM
Hello Patrick,

A possible approach is to save the filter expression onto a viewstate or session variable or any other similar instance and then load the filter expression in the Page PreRender event so as to save filter on postback. For guidance, you can refer this link but you would have to alter the logic according to your requirement.
Saving grid settings on a per user basis

Thanks
Princy.
0
Patrick Wassmer
Top achievements
Rank 1
answered on 11 Dec 2008, 02:09 PM
It works, thx :)
But it's strange that it is not a standar radgrid behavior...
0
Riccardo
Top achievements
Rank 1
answered on 16 Nov 2011, 11:38 AM
Hi, 

I know it's un old post. But I click on the link of the solution and i don't find the page.
I think my problem with the RadGrid it's the same:
I have a list of item in the grid. I filter them and this work fine.
I try to edit one of the filtered list and the Radgrid edit the first element of the non-filter list.

It's seems the Radgrid "lose" the filter. Beyind some code.

<

 

telerik:RadGrid ID="RadGrid1" runat="server"

 

 

GridLines="None" EnableViewState="true"

 

 

Skin="Black"

 

 

DataSourceID="UsersDataSource"

 

 

DataKeyNames="IdUser"

 

 

ShowStatusBar="True" Width="99%"

 

 

Height="418px" AllowMultiRowSelection="false" AllowFilteringByColumn="True"

 

 

 

OnUpdateCommand="RadGrid1_UpdateCommand"

 

 

OnInsertCommand="RadGrid1_InsertCommand"

 

 

OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"

 

 

OnItemCreated="RadGrid1_ItemCreated"

 

 

OnPreRender="RadGrid1_PreRender"

 

 

 

AllowPaging="True" PagerStyle-Visible="true"

 

 

meta:resourcekey="RadGrid1Resource1" AutoGenerateColumns="False" PageSize="7"

 

 

>

 

 

<MasterTableView AutoGenerateColumns="False"

 

 

 

ClientDataKeyNames="IdUser"

 

 

AllowFilteringByColumn="true"

 

 

 

 

DataKeyNames="IdUser"

 

 

DataSourceID="UsersDataSource"

 

 

 

CommandItemDisplay="Top" Width="99%">

 

 

<PagerStyle Mode="NumericPages"></PagerStyle>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<Columns>

 

 

<telerik:GridButtonColumn ButtonType="ImageButton" ImageUrl="~/images/toolbar/Edit.gif"

 

 

CommandName="Edit" UniqueName="btnEdit" meta:resourcekey="GridButtonColumnResource1" />

 

 

<telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false" >

 

 

<HeaderTemplate>

 

 

<asp:CheckBox ID="SelectCheckBox" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True"

 

 

runat="server"></asp:CheckBox>

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

<asp:CheckBox ID="SelectCheckBox" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True"

 

 

runat="server"></asp:CheckBox>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridBoundColumn DataField="IdUser" HeaderText="IdUser"

 

 

UniqueName="IdUser" />

 

 

<telerik:GridTemplateColumn DataField="UserName" HeaderText="UserName" UniqueName="UserName"

 

 

meta:resourcekey="GridTemplateColumnResource1">

 

 

<ItemTemplate>

 

 

<asp:Label runat="server" ID="lblUsername" Text='<%# Eval("UserName") %>' meta:resourcekey="lblUsernameResource1"></asp:Label>

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<asp:TextBox runat="server" ID="txtUserName" Text='<%# Bind("UserName") %>' meta:resourcekey="txtUserNameResource1" />

 

 

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUserName"

 

 

ErrorMessage="*" runat="server" Display="Dynamic" meta:resourcekey="RequiredFieldValidator1Resource1" />

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn DataField="Password" HeaderText="Password" UniqueName="Password"

 

 

meta:resourcekey="GridTemplateColumnResource2">

 

 

<ItemTemplate>

 

 

<asp:Label Text="****" ID="lblPassword" runat="server" meta:resourcekey="lblPasswordResource1" />

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Text='<%# Bind("Password") %>'

 

 

meta:resourcekey="txtPasswordResource1" />

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridBoundColumn DataField="MailAddress" HeaderText="Mail" UniqueName="MailAddress"

 

 

meta:resourcekey="GridBoundColumnResource2" />

 

 

<telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="FirstName"

 

 

meta:resourcekey="GridBoundColumnResource3" />

 

 

<telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="LastName"

 

 

meta:resourcekey="GridBoundColumnResource4" />

 

 

<telerik:GridBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description"

 

 

meta:resourcekey="GridBoundColumnResource5" />

 

 

<telerik:GridDropDownColumn UniqueName="IdDirectory" ListTextField="Name" ListValueField="IdDirectory"

 

 

DataSourceID="DirectoryDataSource" HeaderText="Directory" DataField="IdDirectory"

 

 

DropDownControlType="RadComboBox" meta:resourcekey="GridDropDownColumnResource1" />

 

 

<telerik:GridDropDownColumn UniqueName="IdGroup" ListTextField="Name" ListValueField="IdGroup"

 

 

DataSourceID="GroupDataSource" HeaderText="Group" DataField="IdGroup" DropDownControlType="RadComboBox"

 

 

meta:resourcekey="GridDropDownColumnResource2" />

 

 

<telerik:GridDropDownColumn UniqueName="IdLang" ListTextField="Description" ListValueField="IdLang"

 

 

DataSourceID="LanguageDataSource" HeaderText="Language" DataField="IdLang" DropDownControlType="RadComboBox"

 

 

meta:resourcekey="GridDropDownColumnResource3" />

 

 

<telerik:GridDropDownColumn UniqueName="IdentificationType" ListTextField="IndDescription"

 

 

ListValueField="IndValue" DataSourceID="IdentificationTypeDataSource" HeaderText="Identification Type"

 

 

DataField="IdentificationType" DropDownControlType="RadComboBox" meta:resourcekey="GridDropDownColumnResource4" />

 

 

<telerik:GridDropDownColumn UniqueName="FlgEnabled" ListTextField="IndDescription"

 

 

ListValueField="IndValue" DataSourceID="FlgEnabledDataSource" HeaderText="Enabled"

 

 

DataField="FlgEnabled" DropDownControlType="RadComboBox" meta:resourcekey="GridDropDownColumnResource5" />

 

 

<telerik:GridButtonColumn ConfirmText="Confirm to delete ?" ConfirmDialogType="RadWindow"

 

 

ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"

 

 

UniqueName="DeleteColumn" meta:resourcekey="GridButtonColumnResource2">

 

 

<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />

 

 

</telerik:GridButtonColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

<%

--<HeaderStyle Width="100%" />--%>

 

 

<ClientSettings AllowColumnsReorder="True" >

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True" />

 

 

<Selecting AllowRowSelect="true" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

0
Shinu
Top achievements
Rank 2
answered on 16 Nov 2011, 11:46 AM
Hello Ricardo,

Check the following demo.
Grid / Persisting Grid Settings

-Shinu.
0
Riccardo
Top achievements
Rank 1
answered on 16 Nov 2011, 12:39 PM
Hi Shinu,

i explain you better my problem.
I have a grid with the Employee of a Company and i want to search a Employee for edit them. I filter the Employee by Name for example. I edit one of the filtered rows, supposed IdEmployee 171.
The grid automaticaly rebind and the Edit forms start to Edit IdEmployee 40 (the first Employee of no-filter list)

I don't understand very well how to use Persisting Grid Settings in my purpose.

Thanks in advance.

Riccardo Fanetti.
Tags
Grid
Asked by
Patrick Wassmer
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Patrick Wassmer
Top achievements
Rank 1
Riccardo
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or