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

[Solved] How do I save filter values in a cookie?

1 Answer 620 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saqib
Top achievements
Rank 1
Saqib asked on 23 Jun 2009, 03:41 PM

I have a RadGrid with google like filtering working on it. I am creating all the columns based on the columns returned in a DataSet.. so no binding in my ASCX. I want to save the value from the filter in a cookie so that the user doesnt have to filter it on the next visit. I have tried to implement the grdsavingsettingsonperuserbasis.html code but the problem is where to save the filter in a cookie? The google like filtering is in a RadGrid class file which extends some RadGrid methods and you cannot set/access cookies from there. I am pasting my code to better understand that.

Thanks in advance,
Saqib

ASCX:

 

<

 

radG:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AllowPaging="True"  

 

AllowSorting="True" AllowFilteringByColumn="True"  

 

OnNeedDataSource="RadGrid1_NeedDataSource" OnColumnCreating="RadGrid1_ColumnCreating" OnItemCommand="RadGrid1_ItemCommand" 

 

OnItemDataBound="RadGrid1_ItemDataBound">  

 

<MasterTableView EditMode="InPlace" DataKeyNames="SubmitId" AllowFilteringByColumn="True" AllowMultiColumnSorting="true" /> 

 

<PagerStyle Mode="NextPrevAndNumeric" />
<Columns

 

</Columns>  

 

 

 

</radG:RadGrid

 

 

C# Code Behind:

 

public

 

partial class QueueGoogleLikeFiltering : PortalModuleControl 

 

 

 

 

DataSet ds; 

 

 

#region

Page Init  

 

 

 

protected void Page_Init(object sender, EventArgs e)

 

string str = this.RadGrid1.MasterTableView.FilterExpression;

 

 

GridSettingsPersister settings = new GridSettingsPersister(RadGrid1);  

 

if (Request.Cookies["RadGrid1Settings"] != null)

{
settings.LoadSettings(

Convert.ToString(Request.Cookies["RadGrid1Settings"]["Data"]));  

 

 

}

}

 

 

#endregion

#region

Page Load  

 

 

protected void Page_Load(object sender, System.EventArgs e)

 

try

 

if (!IsPostBack)

{

SetPanels(

Panels.Grid);  

 

 

ds = GetDataSet(); 

 

 

this.RadGrid1.MasterTableView.Columns.Clear(); 

 

 

//Add Submit Id button to the Grid  

 

 

GridButtonColumn gridButtonColumn = new GridButtonColumn();

 

RadGrid1.MasterTableView.Columns.Add(gridButtonColumn);

RadGrid1.MasterTableView.Columns.Add(

 

new GridButtonColumn());

 

gridButtonColumn.UniqueName =

"SubmitId";  

 

 

gridButtonColumn.DataTextField =

"SubmitId";  

 

 

gridButtonColumn.HeaderText =

"SubmitId";  

 

 

gridButtonColumn.DataType =

typeof(int);  

 

 

gridButtonColumn.SortExpression =

"SubmitId";  

 

 

gridButtonColumn.ShowSortIcon =

true;

 

 

 

gridButtonColumn.CommandArgument = ds.Tables[0].Columns[

"SubmitId"].ToString();

 

 

gridButtonColumn.CommandName = "

processForm";

 

 

 

 

 

 

 

foreach (DataColumn dataColumn in ds.Tables[0].Columns)

 

if (dataColumn.ColumnName != "SubmitId" && dataColumn.ColumnName != "Locked")

{

RadGrid.

MyCustomFilteringColumnCS gridColumn = new RadGrid.MyCustomFilteringColumnCS();  

 

 

 

this.RadGrid1.MasterTableView.Columns.Add(gridColumn);

 

gridColumn.DataField = dataColumn.ColumnName;

gridColumn.HeaderText = dataColumn.ColumnName;

}

}

}

}

 

 

catch (Exception ex)

{

lblMessage.Text =

"PageLoad() " + ex.Message;  

 

 

}

}

 

 

#endregion

#region

Grid Bind DataSource Event 

 

 

protected void RadGrid1_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)

 {

ds = GetDataSet(); 

 

this.RadGrid1.DataSource = ds;  

}

 

 

#endregion

#region

Grid Item Data Bound Event  

 

 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

 

try

 { 

 

if (e.Item is GridDataItem)

 { 

 

GridDataItem item = (GridDataItem)e.Item;

 

(item[

"SubmitId"].Controls[0] as LinkButton).CommandArgument = item.GetDataKeyValue("SubmitId").ToString();

 

 

}

}

 

 

 

catch (Exception ex)  

{

lblMessage.Text =

"RadGrid1_ItemDataBound() " + ex.Message;

 

 

}

}

 

 

 

 

#endregion

#region

Grid Column Creating Event  

 

 

 

protected void RadGrid1_ColumnCreating(object sender, Telerik.WebControls.GridColumnCreatingEventArgs e)

 

try

{

 

if (e.ColumnType == typeof(RadGrid.MyCustomFilteringColumnCS).Name)

{

e.Column =

new RadGrid.MyCustomFilteringColumnCS();

 

 

}

}

 

 

 

catch (Exception ex)  

{

lblMessage.Text =

"RadGrid1_ColumnCreating() " + ex.Message;

 

 

}

}

 

 

#endregion

MyCustomeFilteringColumnCS.cs is the same as described in the Google Like Filtering example.


GridSettingsPersister.cs is the same as described in grdsavingsettingsonperuserbasis.html example.

Any help would be appreciated.

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Jun 2009, 01:28 PM
Hello Saqib,

If you have implemented the GridPersister class as shown in the example cited by you, then you can pass as a parameter to the LoadSettings and SaveSettings methods the HttpRequest object which is completely valid since those methods are called during the HttpRequest handling cycle.

I hope this information helps.

All the best,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Saqib
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or