in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Bob's SharePoint Bonanza

Filtering with SPGridView

One of the most exciting new web controls that come with SharePoint 2007 is the SPGridView control. With it, you can present data in a grid view that closely resembles the view that SharePoint uses to display data from lists. You can sort and group rows, add drop-down menus to cells and filter rows using column header drop-down menus.

There is, however, a slight drawback with it; there is almost no official documentation on how to use it. But there is lots of information post on it around the 'net. If you're new to the SPGridView, I suggest you head over to Powlo's blog that has a great introduction of how to use the basic features of the control.

I recently chose to use this control in a scenario where filtering using the UI was required. I had heard about the SPGridView and knew it had the filtering capabilities I needed, but I had a very hard time figuring out how to use it. But after much (unsuccessful) Googling and a lot of trial-and-error on my own, I managed to get it right and thought it would be nice to share this information with others facing the same challenges I did.

The first hurdle I ran into was that filtering does not work if you bind the SPGridView using the DataSource property; you have to use the DataSourceID property to perform the binding. For this example, I wrote a small class that creates a DataTable object with some hardcoded data:

public static class ExampleObjectDataSource
{
  public static DataTable GetDataTable()
  {
    DataTable tblData = new DataTable();
    tblData.Columns.Add("Title");

    tblData.Columns.Add("Author");

    tblData.Columns.Add("Rating");

    tblData.Rows.Add("Obsession", "Robards, Karen", 2);
    tblData.Rows.Add("Vanished", "Robards, Karen", 3);
    tblData.Rows.Add("Magician: Apprentice", "Feist, Raymong E.", 4);
    tblData.Rows.Add("Magician: Master", "Feist, Raymong E.", 5);
    tblData.Rows.Add("Silverthorn", "Feist, Raymong E.", 4);
    tblData.Rows.Add("Lord Foul's Bane", "Donaldson, Stephen R.", 3);
    tblData.Rows.Add("The Illearth War", "Donaldson, Stephen R.", 4);

    tblData.AcceptChanges();

    return
tblData;
  }
}

Then simply instantiate an ObjectDataSource object that points to the example data class in the CreateChildControl() method of the web part:

ObjectDataSource odsDataSource = new ObjectDataSource(
 
"Strand.Demos.FilteredGridExample.ExampleObjectDataSource, Strand.Demos.FilteredGridExample, Culture=neutral, Version=1.0.0.0, PublicKeyToken=9f4da00116c38ec5",
  "GetDataTable"
);
  odsDataSource.ID = "ExampleSource";
  Controls.Add(odsDataSource);

Of course, we're going to need some columns to display the data. For good measure, I want to implement sorting as well, so let's set the SortExpression properties of the fields too:

sgvGrid = new SPGridView();
sgvGrid.ID = "ExampleGrid";
sgvGrid.AutoGenerateColumns = false;

BoundField
col = new BoundField();

col.DataField = "Title";
col.SortExpression = "Title";
col.HeaderText = "Title";
sgvGrid.Columns.Add(col);

col = new BoundField();
col.DataField = "Author";
col.SortExpression = "Author";
col.HeaderText = "Author";

sgvGrid.Columns.Add(col);

col = new BoundField();
col.DataField = "Rating";
col.SortExpression = "Rating";
col.HeaderText = "Rating";

sgvGrid.Columns.Add(col);

sgvGrid.AllowSorting = true;

Next, let's enable the filtering!

sgvGrid.AllowFiltering = true;

Now, we need to tell the SPGridView which columns we want to enable filtering on, and which field each column should use in the filter expression by setting the FilterDataFields property. This is a comma-separated string containing which field each respective column in the grid should filter by. We want to be able to filter by Author or Rating, but not by Title, so leave the first field empty:

sgvGrid.FilterDataFields = ",Author,Rating";

We also need to tell the grid which property to set on the data source control when filtering. In our case, it is the FilterExpression property of the ObjectDataSource:

sgvGrid.FilteredDataSourcePropertyName = "FilterExpression";

The SPGridView control will use string.Format() to generate the string it will set the FilterExpression to, so we must specify the format string it will use. The first parameter is the value to filter on, and the second parameter is the name of the field being filtered.

sgvGrid.FilteredDataSourcePropertyFormat = "{1} LIKE '{0}'";

And lest we forget, let's set the DataSourceID property of the grid and add the grid to the Controls collection:

sgvGrid.DataSourceID = "ExampleSource";
Controls.Add(sgvGrid);

Do the databinding in the Render method:

protected override void Render(HtmlTextWriter writer)
{
 
sgvGrid.DataBind();
 
base.Render(writer);
}

Now you'll have filtering implemented and you can compile, deploy and filter the grid to your heart's content!

(Please excuse the Swedish UI!)

If you've come this far and played around with the filtering and sorting for awhile, you've probably noticed that there's something that's not working quite as you'd expect it; If you filter by one column and then sort by another, your filter will disappear! This is of course highly unsatisfactory and needs to be dealt with!

I think my solution to this is a bit on the ugly side, so if anyone out there happens to know the "right" way of doing this, I'd appreciate it if you let me know!

What I did was to first save the FilterExpression in the ViewState in the OnPreRender method:

protected override void OnPreRender(EventArgs e)

  ViewState["FilterExpression"] = odsDataSource.FilterExpression;

  base
.OnPreRender(e);
}

Then I inserted code to set the FilterExpression to the previously saved expression in the ViewState. Since I never want the options in the filter menu drop-down to be filtered, I check the query string and then only set the FilterExpression if the current page request is not callback from the drop down menu. This code should be inserted just before adding the odsDataSource object to the Controls collection:

HttpRequest req = HttpContext.Current.Request;
if (req.Form["__CALLBACKID"] == null ||
  req.Form["__CALLBACKPARAM"] == null ||
 
!req.Form["__CALLBACKID"].EndsWith("ExampleGrid"))
{
 
if (ViewState["FilterExpression"] != null)
   
odsDataSource.FilterExpression = (string)ViewState["FilterExpression"];
}

And that's it!

Comments

 

pccai1983 said:

Very Good post!

July 4, 2007 11:43 AM
 

Marius C. said:

Interesting post and valuable, thank you for that!

I would have a question though: Wouldn't it work as with any list in SHarePoint to filter/sort by using the URL format, e.g. ro1cv6hc/.../AllItems.aspx - used to filter after file type, here .doc?? Or does it apply only for SharePoint based data-sources??

July 5, 2007 5:01 AM
 

Robert Fridén said:

Hi Marius.

I'm happy to hear you liked the post!

Using the URL to perform filtering only works with lists actually stored in SharePoint. "AllItems" in this case is the view of the list you wish to filter. The SPGridView is a Control you can use in your own web parts and can contain any data stored anywhere as long as you have a way of accessing it from your code.

In my case, I wanted to present search results in a table layout and enable the user to sort and filter the results.

July 26, 2007 8:21 AM
 

Mike said:

Hi,

Thanks for sharing this, it was very helpful.  Unfortunately it appears that Sharepoint filtering does not work with connect web parts.  I connected the grid view to a provider that supplies a date, and the filter drop-down list show 'loading..' and then disappears.  When I disconnect the web parts, it works fine.  Any ideas as to how I can get filtering to work with connected web parts?  Thanks for any help.

-Mike

July 30, 2007 4:41 PM
 

Allan said:

Nice post!

I am trying to get the code working with a DataView instance instead of the ObjectDataSource, but by some it reason I can't get it running. Shouldn't that be possible?

Has anyone tried to use a DataView with the code?

Any help will be appreciated

- Allan

August 2, 2007 6:34 AM
 

Robin said:

Blogged you at :

glorix.blogspot.com/.../i-l-spgridview.html

Thanks alot!

August 8, 2007 6:41 AM
 

Mirrored Blogs said:

Currently I'm busy with redeveloping some 'old' 2003 webparts and quite often I used a .NET

August 8, 2007 7:00 AM
 

Decosta said:

Hello Bob,

I have done as per your instruction however I noticed that while trying to debug the web part, the control does not go to the render method. Could you let meknow why this is occurring. Should I do something else as well to make it work?

August 14, 2007 4:51 AM
 

Greg said:

I have implmented your code and it works greate for one column. However, I need it to work for multiple columns. If you filter on a regular SharePoint list you can filter on one column, and then filter on another column and the two filters work together. However, with this technique, you can only filter on one column at a time. Has anyone figured out how to filter on multiple columns yet?

August 16, 2007 12:16 AM
 

filion said:

Hey Mr Bonanza,

I wanted to try your code but in my case, it is not possible to use a static objectDataSource having a GetMethod without any parameters since  I m getting the data from the XML ouput of CoreSearchResult (XMLDocument converted to DataSet/DataTable). Is there any workaround to make filtering available on my Datagrid. Everything else is working fine..sort, page, that`s the only thing left I need to implement. Thanks in advance

-Phil

August 16, 2007 2:17 PM
 

marry said:

Hi BOB,

Could you let me know the filter expression that can be used to implement multiple field filter in ahierarchichal order?

Like the statement :

spgridview.FilteredDataSourcePropertyFormat = "{1} LIKE '{0}'"

provides us the option to perfom filter on one field at a time. How can we perform mutiple filter on the columns in the above stement?

August 17, 2007 3:43 AM
 

Antoine said:

Hello

Tanks for this good article.

but i have a problement in the filter list element.

they display 'loading...' and nothing happen !!!

so i can't use filter.

any idea ?

August 22, 2007 4:44 AM
 

Singh said:

hii.Thanks for the infoemation.Its really very helpful.Always put these kinds of information ovet the net so that could be useful for others.

August 23, 2007 10:43 PM
 

oleposya said:

How to render an image in spgridview column? like it is done in imagefield in gridview column?

August 29, 2007 3:14 PM
 

Robert Fridén said:

oleposya: Yes, you do it the same way. Just add an ImageField to the columns collection and set the DataImageUrlField property and optionally the DataAlternateTextField property. If you want to constrain the width of the field you can set the HeaderStyle.Width and ItemStyle.Width properties of the ImageField object.

August 30, 2007 9:18 AM
 

Robert Fridén said:

Greg and marry: That's a really good question. I haven't researched how to allow filtering for multiple columns, but there doesn't seem to be any obvious way to do it. I suspect you'll have to implement some custom logic to combine the old and the new filter string during postback. If anyone finds a good way to do this, please let me know!

August 30, 2007 9:23 AM
 

Robert Fridén said:

filion:

I also used the SPGridView to display search results with filtering and sorting. My solution was to create a kind of Singleton class that automatically managed it instances per HttpContext. This class performed the search (using FullTextSqlQuery in my case) which I could access from my static GetDataTable class.

Maybe a workaround for you could be to set a static member variable using your XML that you later can retrieve in GetDataTable?

August 30, 2007 9:34 AM
 

Oleposya said:

All I found were DataBound fields and Menu fields

SPboundField col1 = new SPBoundField();

SPMenuField col2 = new SpMenuField():

what is the name for ImageField type?

I also didn't find any examples on www on how ppl are using it - or adding template columns to SPGridView.

I just need to display different images depenging on my storedProcedure results

.. and so far I can't find it.

August 30, 2007 12:17 PM
 

Oleposya said:

I guess I assumed that there suppose to be a special "SP" version for a "special SPGridView" version of Gridview - for ImageField column as well and can't find it. I will try to add this column by directly referring to "non-SP" webcontrols class and ImageField and see how it work.  

August 30, 2007 12:58 PM
 

Oleposya said:

yes - worked very good - sorry for bothering you with such a simple question :)

August 30, 2007 1:59 PM
 

Preeti Nair said:

Hi Mary , chipzter , and greg:

I have come up with a custom solution for the multiple column filter:

Use a string to hold the prev filter value.

In the createchildcontrol() section place this code instead of the current one which is shown:

HttpRequest req = HttpContext.Current.Request;

           if (req.Form["__CALLBACKID"] == null || req.Form["__CALLBACKPARAM"] == null || !req.Form["__CALLBACKID"].EndsWith("ExampleGrid"))

           {

               if (ViewState["FilterExpression"] != null)

               {

                   odsDataSource.FilterExpression = (string)ViewState["FilterExpression"];

                   PrevFilter = (string)ViewState["FilterExpression"];

               }

           }

Then in the Render section place this condition and check out before you buind the spgridview:

if (PrevFilter == string.Empty)

                   odsDataSource.FilterExpression = ViewState["FilterExpression"].ToString();

               else if (PrevFilter != string.Empty && ViewState["FilterExpression"].ToString() == string.Empty)

                   odsDataSource.FilterExpression = "";

               else if (PrevFilter != string.Empty && ViewState["FilterExpression"] != null)

                   odsDataSource.FilterExpression = PrevFilter + " and " + ViewState["FilterExpression"];

August 31, 2007 4:49 AM
 

bazztrap said:

Well in the example ...

You aren't checking if the filter which is being set is for a different field or its for same field. Or else it will throw an error

trying to filter on same field twice.

Ideally you could store an hahtable of field values in viewstate  where key would be Field Name and whenever same field is clicked append latest value to it.

Also you may have to figure a logic to clear the filters out. ( there is an option to do that)

OnFilter event may be usefull here. detecting which column was hit and clear the key of the hash table

August 31, 2007 9:37 AM
 

bazztrap said:

For Image field

Using  custom datatable as your datasource.  

Append the image URL to be displayed as an HTML image tag.

EG

foreach(DataRow dr in DataTable.Rows)

{

dr["Image"] =  string.format("< Img  src  ='{0}' /> ", dr["Image"].ToString());

}

Simplest way would be :

sgvGrid = new SPGridView();

sgvGrid.ID = "ExampleGrid";

sgvGrid.AutoGenerateColumns = false;

BoundField col = new BoundField();

col.DataField = "Image"; <---- this field you just appended

col.HeaderText = "Image";

col.HtmlEncode =False; <---  This will make the column render in html format instead of dsiplaying html tags in the column

sgvGrid.Columns.Add(col);

--- Databind

DOEN DONE

August 31, 2007 9:49 AM
 

bazztrap said:

I was wondering if a custom Datatable could be wrapped in some other data source just to remove Static class dependencies ?  

September 4, 2007 10:59 AM
 

Paras said:

Hi...

I m not getting AllowFiltering property to set it true for that What should i do???

Please do reply its urgetn

September 5, 2007 3:39 AM
 

Grossmeister said:

How can I filter data if I'm using SPList as DataSource?

September 11, 2007 2:32 AM
 

krish said:

Hi,

I am trying bind the Type field of document library to the SPGridview.  here i am using SPDatasource to bind the SPGridview. Can you suggest how i can bind the "Type" field so that i can display the associated image of the folder of document  in my custom gridview.

thank you

September 24, 2007 8:44 AM
 

GustavoFerreira said:

For display lookup field  in the correct way, use SPBoundField instead BoundField.

October 4, 2007 10:52 AM
 

Smack said:

Hi,

How can we set two fields value as a text for single field using SPGridView. Is there any way to do this.

Ex: Say a list has fields with FirstName, LastName, Email, etc.

Now using SPGridView and BoundField can't we combine the fields FirstName and LastName and show them as FullName.

Thanx in Advance.

October 9, 2007 5:17 AM
 

Roona said:

Mine works perfect using Preeti Nair addition for multi column filtering until i add the controls to a panel. Does anyone know why this would be?

October 13, 2007 6:56 AM
 

CList said:

Is it just me or does the current DataGrid-based implementation seem very inefficient? I mean, what do you guys do if you have a datasource pulling 2000 rows from a database pre-filter? To have that amount of data get pulled from a database, and then to filter it down to maybe 400 rows, and then to page that down to just 20 rows to server to the browser seems completely ridiculous.

It would be so nice if we could just set PageCount for the pager  ourselves wit a quick SELECT count(*) base don the current filter, and then load the datasource with only the rows we need based on the filter and pager-position each time we do a DataBind. Setting the paging can be done on the db server side with some fancy (but not too difficult) "select top x" queries on the DB side.  Alas, PageCount is a read-only property.

I'm thinking of implementing a custom paging control in my SPGridView web part to allow me to do what I described.

Am I missing something here or do most people just have either small datasets or ignore the inefficiencies in the existing system just to get their app built quickly?

Cheers,

CList

October 19, 2007 10:46 AM
 

Roona said:

I think all these comments should be moved to a better forum as this is the best documentation of spgridview on the net. Would someone care to move it?

Great code has been written here and could be very beneficial for other developers and further enhancements.

I have a working version in VB but is a bit buggy. But with some good communication we could nail this.

October 23, 2007 8:56 PM
 

Martin said:

Thanks for a great post!

I've an issue where I need to filter on a Date column, and I need to set the display format for the date (like YYYY/DD/MM) to be displayed in the filter.

In the BoundField I can do something like:

bf.DataFormatString = "{0:d}";

Which works fine, but the timestamp still shows up as 00:00:00 in the filter.

Any ideas/help would be appreciated.

October 31, 2007 5:24 AM
 

ic said:

Very helpful article. Thanks!

The question is how to filter columns of different types, for example 'string' and 'date' and 'int'. Each of them needs different filtering expression. String needs to be enclosed in single quotation marks, date must be enclosed in within '#' characters, int doesn't need to be enclosed at all. So how to properly use FilteredDataSourcePropertyFormat property of SPGridView?

Thanks in advance.

December 9, 2007 12:28 PM
 

ic said:

...continuing...

I am not completely sure that i am right about filtering expressions in my previous post but i am making assumptions based on  a DataColumn.Expression property.

December 9, 2007 1:44 PM
 

bazztrap said:

you coukld use Page.IsCallback()

December 27, 2007 2:21 PM
 

Morten Andersen said:

The original sharepoitn list view webpart has an menu item called "Show Filtering Options" if the list has more than 500 items. SPGridVIew does not seem to implement the same feature, which makes it very heavy to filter when more than a couple of thousand items are in the list.

Or have anyone found a solution to this.

January 29, 2008 4:13 AM
 

Babangida said:

Please can anybody help me on how to format the width of spgridview columns.

February 15, 2008 5:44 AM
 

Babangida said:

Please can anybody help me on how to format the width of  sharepoint Gridview(spgridview) columns,that is customising the width of the bound columns.

February 15, 2008 5:47 AM
 

Tom said:

Great post!

One question though... Did anyone test Preeti's solution for sorting on multiple columns? I've just implemented his solution and it doesn't seem to work at first sight... I'll do some more testing tomorrow, but if anyone could already tell me if they already tested it and/or have a working solution, it might save me quite some time!

February 18, 2008 9:02 AM
 

luca said:

interesting article.

I just finished this example and powlo's famous SPMenuField example,but i only had two same exceptions, which was about 'template property must not be null,and the control's template property must be initialized'. I'm totally confused,is it because I use the WSS3? can anybody have solution on this situation?

February 22, 2008 2:33 AM
 

Tom said:

Just a quick note: I got the multiple filtering to work! If you're interested in the full solution, check out my blog, I'll post it there one of these days.

To quickly sum up what I did: I created a custom web part property, scoped for the user, and saved the filtering there and then added extra values with " and " before it. I also implemented the option to include multiple values of one column with an " or " expression.

Because you're using web part properties in stead of a simple string, it remembers all values in stead of only two and it also remembers your filtering settings when you leave the page.

March 7, 2008 2:50 AM
 

basquang said:

any source here?

March 20, 2008 11:00 PM
 

rajeev said:

how to do filtering on string of this format- 'rajeev'house in 12'th main'. Because of ' character, it is not able to filter . can any one have idea regarding that

April 4, 2008 7:52 AM
 

mark parter said:

I'm trying to get this to work in an ASP.NET page within SharePoint, NOT within a web part. I can get the SPGridView to bind to a SQLDataSource and page OK, bu the filtering doesn't work.

I presume it's similar to the filtering on a list, it's a drop-down list from the column heading?

April 17, 2008 4:35 AM
 

Michael said:

It seems that the GetDataTable gets called twice for every page load.  Does anyone know why this is?

April 23, 2008 9:50 AM
 

Nirav said:

I am new in using ObjectDataSource.

I need to pass arguments base on user inputs to generate datasource as per.

In this case something like

public static class ExampleObjectDataSource

{

 public static DataTable GetDataTable(DateTime sDate, int EmpId)

 {

   DataTable tblData = new DataTable();

  /// code to generate DataTable as per date and EmpID

...

...

}

}

can you tell how to pass this two arguments when creating odsDataSource.

ObjectDataSource odsDataSource = new ObjectDataSource(

 "Strand.Demos.FilteredGridExample.ExampleObjectDataSource, Strand.Demos.FilteredGridExample, Culture=neutral, Version=1.0.0.0, PublicKeyToken=9f4da00116c38ec5",

 "GetDataTable");

 odsDataSource.ID = "ExampleSource";

???

???

May 3, 2008 3:40 AM
 

Joel Corra said:

Nirav-

You put the arguments in the SelectParameters collection of the ObjectDataSource.  If the values are coming from other controls on the page/in your webpart, then you'll want to add an event handler for the ObjectDataSource's Selecting event and add the parameter values there.

May 15, 2008 4:11 PM
 

Dinesh said:

Very good post

May 28, 2008 6:26 AM
 

Custom Filters in SPGridView « Ketul’s Weblog said:

Pingback from  Custom Filters in SPGridView &laquo; Ketul&#8217;s Weblog

May 30, 2008 5:59 PM
 

Moorthy said:

Hi,

Currently i have enabled Grouping and sorting in SPGridView.

I need to sort the items based on Group field but for me the items got sorted and then its getting grouped.

Pls help me to Sort the items based on Grouping.

June 9, 2008 7:41 AM
 

Moorthy said:

Hi,

Currently i can able to GroupFields in GridView and if I enable sorting then more than one Grouping for single groupfield appears.

I need to Sort items within GroupField.

Pls help me.

June 9, 2008 11:10 PM
 

Seamus said:

Thanks... Allan asked

I am trying to get the code working with a DataView instance instead of the ObjectDataSource, but by some it reason I can't get it running. Shouldn't that be possible?

Has anyone tried to use a DataView with the code?

I need the same - did anyone have any success?

Best wishes

June 30, 2008 5:11 AM
 

Terrabit - Alex said:

Hi guys,

here an sample for filtering columns with different datatype:

           oGrid.DataKeyNames = new stringDevil { "Status", "ProdOrderNo", "RoutingReferenceNo", "RoutingNo", "OperationNo", "Description" };

           oGrid.FilterDataFields = ",StartingDate,EndingDate,RoutingStatus";

           oGrid.FilteredDataSourcePropertyName = "FilterExpression";

           oGrid.FilteredDataSourcePropertyFormat = "IIF('{1}' = 'StartingDate' OR '{1}' = 'EndingDate',{1} = '#{0}#',{1} = '{0}')";

           oGrid.AllowFiltering = true;

July 21, 2008 8:46 AM
 

Dudi Nissan said:

Hello,

If I do the databinding in the Render method, I get "Object Reference" exception because the SPGridView is null.

If I do the databinding in the CreateChildControls method, I get the following error: "The SPGridView control 'mySPGrid' does not have a naming container.  Ensure that the control is added to the page before calling DataBind"

Any Ideas?

Thank you.

July 25, 2008 2:30 PM
 

Dudi Nissan said:

I solve the problem myself:

I did the databinding in the CreateChildControls method after Controls.Add(SPGridiew).

July 27, 2008 3:35 AM
 

Joycode@Ab110.com said:

&#160;&#160;&#160; 我们在SharePoint上查看列表视图的时候,默认的那个Web部件(ListViewWebPart)提供了丰富且友好的功能,可以在上面进行排序、筛选等操作,每个列表条目上还有一个友好的下拉菜单

July 30, 2008 4:50 AM
 

Arun said:

Hello Bob,

Thank you for sharing the information.

I have a problem with Sorting of SPGridView control in a custom webpart. At first, sorting of SPGridView works perfectly when I click on the column header link as well as dropdown menu item.

But if I place more than one instance of same webpart in a page, I am experiencing a strange problem when the drop down menu is used for sorting selection. No matter what webpart instance is clicked,it only sorts the FIRST webpart in the page. Also there is no problem when the column header link is clicked, it works fine.

I tried many workarounds, but couldn’t solve the issue. Is this happens with multiple gridviews in a same page?

I

Please help me.

Thanks in advance!

-Arun

August 15, 2008 5:16 AM
 

Nik said:

Hi Bob,

Same problem here.

When there is only one webpart in the page, everything works fine. But when one more is added, sorting is becoming weired. When sorting menu item of the second webpart is clicked, the first webpart gets sorted. The webpart on wheich the drop down menu item is clicked remains unchanged. But sorting works when the column title is clicked instead of the dropdown menu.

Thank you,

August 18, 2008 2:12 AM
 

Tester said:

:-)

August 18, 2008 5:55 AM
 

Oliver Wirkus said:

Very good work :-)

The only thing I'm missing is the little filter icon indicating that the data that is displayed is filtered.

Does anybody know how to add this little icon in case filtering is active?

Regards,

Oliver

August 18, 2008 8:51 AM
 

Oliver Wirkus said:

Just got it done! I managed to get the little cone icon diplayed just next to the filtered column.

If anybody is interessted in how to do it, just have a look on my article - here is the link:

www.sharepointblogs.com/.../how-to-professionelle-datenanzeige-mit-dem-control-spgridview.aspx

Thanks to Robert - without his post I would have had more trouble with my little SPGridView-demo.

August 21, 2008 8:06 AM
 

How to: Professionelle Datenanzeige mit dem Control SPGridView - Meine SharePoint-Notizen said:

Pingback from  How to: Professionelle Datenanzeige mit dem Control SPGridView - Meine SharePoint-Notizen

August 22, 2008 6:20 AM
 

sunil said:

i have 2 dropdown lists Company and Client which are populated from SQL database, i am not able to see the Client DropDown refreshing when I select the Company. Please let me know what is missing from my code below

<asp:DropDownList runat="server" id="ddlCompany" DataSourceID="SqlDataSource1" DataTextField="CompanyName" DataValueField="ID" AutoPostBack="True" DataMember="DefaultView" AppendDataBoundItems="True"></asp:DropDownList>

<asp:DropDownList runat="server" ID="ddlClientName" DataSourceID="dsClientInfo" DataTextField="FirstName" DataValueField="ID" AutoPostBack="true"></asp:DropDownList>

<asp:sqldatasource

 id="SqlDataSourceCtrl"

 runat="server"

 ConnectionString="Data Source=MDS\SQLEXPRESS;User ID=sa;Password=qwerty;Initial Catalog=HanInfo;"

 selectcommand="SELECT * FROM tb_Client WHERE CompanyID = @CID">

 <selectparameters>

     <asp:controlparameter name="CID" controlid="ddlCompany"  propertyname="SelectedValue"/>

 </selectparameters>

<FilterParameters>

<asp:controlparameter ControlID="ddlCompany" PropertyName="SelectedValue" DefaultValue="2" Name="fltCID" Type="Int16" />

</FilterParameters>

</asp:sqldatasource>

August 28, 2008 3:38 AM
 

Edward M. said:

Hi,

After a full day I was unable to get your example working.

Anyway you could post the full project or email it to me?

I know how that sounds, sorry.

September 16, 2008 6:09 PM
 

Mahmoud said:

Can you please explain how can i set the objectDataSource TypeName property?

September 23, 2008 3:27 AM
 

.neting in the free world said:

Nie raz już w różnych przypadkach podawałem wam linki odnoszące się do SPGridView , pora się temu trochę

September 23, 2008 5:33 PM
 

Nakago said:

Hi everyone,

I'm facing the same problem Arun and Nik experiment : everything works great when there's only one instance of the webpart on my page, but when I put two of them, I observe a strange behaviour. Setting a filter is ok, but clearing a filter or sorting on a column is always done on the first webpart, no matter which one I wanted to sort or clear filter.

Does anyone has any idea to solve this problem ? I've been testing for three days and didn't find anything.

Thanks for any help.

September 29, 2008 11:21 AM
 

Nakago said:

Hi,

I got a few more info about my problem while attempting to debug my code.

I clicked on the button "Clear filter from <column name>" in the dropdown menu of one of my SPGridView columns' header, and checked the parameters in the HttpContext.Current.Request (i'll call this object request to make my post more readable).

And I saw that request.Form["__EVENTTARGET"] = ctl00$PlaceHolderMain$GridView1$GridView1 so it contains the id of the first SPGridView I put on my page, even if I tried to clear filter from the second SPGridView.

If I'm not wrong, this parameter should be the id of my second SPGridView, not the first one (so it should be something like ctl00$PlaceHolderMain$GridView2$GridView2), isn't it ? Does anyone has any idea to have the correct parameter here ? (Visual Studio debugger doesn't allow me to change this value at runtime, so I'm not sure it will solve my problem, but I think it's the path to the answer).

Any help is welcome.

September 30, 2008 8:15 AM
 

Eric said:

After 2 days researching. I found out that the filtering function would not work if when paging function is enabled.

October 16, 2008 10:00 PM
 

James said:

Babangida,

For reference

e.g.

 <Columns>

<SharePointWebControls:SPBoundField DataField="__spTitle" HeaderText="Title">  

  <itemstyle width="100px"/>

   </SharePointWebControls:SPBoundField>  

November 20, 2008 4:13 AM
 

Tom said:

Arun, Nik and Nakago, I haven't tried this out myself, but the solution for the "adding multiple SPGridView Web Parts on one page" problem seems pretty easy for me... As the current filter and sort values are being saved in the ViewState, you need to make sure to use other ID's to save these for your different WebParts. I'm afraid you'll have to make a "GridView1" and "GridView2" for example, where the only difference is that they use other ID's, so there is no conflict anymore... (the "ID" I'm talking about is for example the "FilterExpression" in "ViewState["FilterExpression"] ").

November