ASP.NET Controls Filter the Data View

ASP.NET Controls Filter the Data View

Rate This

John Hey there,

My name is John Jansen and I'm one of the Test Leads for the SharePoint Designer (SPD) product group. My specialty is data presentation and application building. But I also love to play around with CSS and generic ASP.NET controls. I plan to post tips and tricks here based on questions I see asked in Newsgroups as well as Discussion Boards inside Microsoft.

This first tip is about inserting an ASP.NET control onto a page in SharePoint Designer and then using that control as the mechanism for filtering a Data View on the page. For the purposes of this post, I'm using a DropDownList control because that seems to be the one most people ask about, but you could use a TextBox or CheckBox or anything else and get similar results. The scenario here is that you have a bunch of Categories and a bunch of Products that fit into those Categories, and you want to use a DropDownList to show Products for a specific Category.

To begin, create two lists in the browser: Categories with a field of CategoryName and Products with a field of CategoryName as well (I use a Lookup field type for simplicity, but it doesn't have to be - this code does a simple string compare). Then fill out the lists so you have more than one item in each.

This tip also assumes you already know how to open your Site in SPD and you have created a new page. I realize it is a lot of steps, but I believe they are pretty straight forward as you perform them...

  1. Place your page into design view
  2. Click Task panes :: Data Source Library
  3. Click the data source called Categories
  4. Click to Insert Data Source Control
  5. If prompted, click “Yes” to display the control
  6. Place insertion point below this control
  7. Click Insert :: ASP.NET Controls > Drop Down List
  8. Click the Smart Panel :: Choose Data Source...
  9. Choose the Data Source (for example, SPListDataSource1)
  10. Tell it to display "CategoryName" (or the field that contains your category name)
  11. Make its value "CategoryName"
  12. Click OK
  13. Click to select the dropdownlist control
  14. Click the Smart Panel :: AutoPostBack == True
  15. Drag and drop the Products list onto a page to create a Data View
  16. Clck the Smart Panel :: Edit Columns to add and remove the columns you want to display
  17. Click Data View :: Filter 
  18. Create the following filter:
                    Field: CategoryName (or the field that contains your category name)
                    Comparison: Equals
                    Value: [Create a new Parameter]
                                    Param Name: Param1
                                    Source: Control
                                    Control ID: DropDownList1
                                    Default: Beverages
  19. Click OK
  20. Click OK again
  21. Save the page
  22. Preview in the browser
  23. Make a change to the DropDownList control

OK. That should do it! Good luck.


  • Is it possible to use this ASP dropdown on a Custom List Form in Sharepoint?  I created a new Form that works fine when I click New on the wss calendar, but when I try to the asp dropdownlist, I get an "unexpected error".

    Any thoughts?

  • I have a sql view data source on a page and I've also added a date filter.  My data source has begin and end date columns.  I'd like to be able to select and date from the date filter and have all rows displayed where the date selected is between the begin and end date.  Can the value from the date filter be accessed by the data source filter using a parameter? I haven't been able to make this work.  Any suggestion would be appreciated.  

  • new to SP designer, filling in for the programmer (who was fired)... I followed the instructions down to step 18.

    Per the instructions, I created 2 lists and a new page, opened it up in SP Designer, inserted data controls for "Categories" and ASP.Net Drop down, I chose the data source using SPListDataSource1 and selected "CategoryName" for the other 2 fields, set Postback = True, drug and dropped Products list onto the page.  Once there I edited the colums and clicked on Data View::Filter.

    Now the issue...... I selected CategoryName for the field, Equals for the Comparison and creted a new parameter called Param1, set to control but my Control ID field is blank.  I cannot select DropDownList1.  What did I do wrong?



  • Hi

    I am able to filter with a dropdownlist and tried using the checkbox list by using your suggestion.

    i.e <ParameterBinding Name="Param1" Location="Control(CheckBox1,Checked)" DefaultValue="foo"/>

    If I am giving some defualt vaule, then its filtering based on that value. but if I select anything else, its not wokring.

    Any help whould be highly appreciated.

  • Hi, great post!!

    Of course its not working exactly as planned...

    I have two drop-downs filtering one list - it works fine with this xslt filter:

    [(@Category = $Param1 or $Param1 = '(All Categories)') and (@Community = $Param2 or $Param2 = '(All Communities)')]

    HOWEVER, when the page is FIRST loaded, the default results aren't shown - it is blank. I guess I could solve this by loading the page and automatically posting back, but this obviously isn't a good idea.

    Is there any way to have the results of the filter be shown on the page when it first loads?


  • Okay, I answered my own question, sort of, I have a work around anyways.

    In addition to what I did as explained above, I also did what the poster said on March 15, 2007 7:38 AM. I appended an item called "-- Please select a value --" but in the VALUE field put in the '(All Communities)'. Seems to work, now when the page loads I still have all of the default values showing up.

    Dave #2

  • All of this doesn't work as soon as you use a wss 3.0 masterpage. It works fine in an empty aspx page.

    With the masterpage the parameter is always set to default and never picks up the actual selected value of the formfield.

  • Hi,

    This is a cool post.

    I'm trying to sort the drop down list in alpha order. However, whenever I do this my data source gets the following error: Duplicate Component Name 'spdatasource5'. Component names must be unique and case-sensitive.

    Anyone got any clue why this would be happening?

  • Hi Jon,

    I have reviewed your Demo's six part series.  I thought they were very helpful.  Thank you.

    I just started working with SharePoint.  I have bought books on sharepoint and browsed ther internet for information.  I have some ASP.Net experience.

    Two things I need to do right a way is design a great looking master page using a team template and the other is to allow internal company users and unkown users to our SharePoint site perhaps using Forms authentication, login/register.  I'm not sure if I'm going to use SQL server asp provider.

    Can you point me in the right direction on these two items?.  Any videos on them?  

    Thank you.

  • Hi John,

            Can we use a similar approach to filter a datasource inside a DataFormWebPart ? Let me give you the scenario, I've got a department list and a section list on my Site. I want to customize the newform of another list to be able to add Cascading DropDown Functionality for selecting a section ( Department->Section) as follows:

    1. Created a datasource (1) to pickup all departments ( Note that Department Field does not exist in my actual list, only Section Field )

    2. Connected an ASP.Net Dropdownlist to the Datasource (DropDownList1) with AutoPostBack

    3. Create another datasource (2) to pickup the sections - Here I inserted {DepartmentName} as parameter in the CAML Query of the Select Method

    4. Linked the Parameter using ASP:ControlParameter to the DropDownList1.

    5. Added a Sharepoint:DataViewDropDownList, linked to the Section Field of the actual list and also linked to datasource (2)


    On opening the form, the list of departments and sections are filled correctly. When selecting another department, postback is performed but the section list does not get refreshed. Is there a fundamental thing I've missed out or this kind of implementation not possible ?

    Thank you

  • Is there any way to use the following field as input for the filter?

    <SharePointWebControls:TextField FieldName="Company"  runat="server" id="TextField1"></SharePointWebControls:TextField>

    We tried to do the same trick with  Control(TextField1,Text) but this isn't working.



  • Hi

    Tried the dropdown dataview filter instructions and it worked perfectly

    I have now set it up to filter on the modified by Field

    I get some strange results in the drop down that includes the the persons name , email etc

    eg. 37;#Sean ,#xxxx\yyyyyyy,,#,#Sean

    The x's and y's I used to replace the original data

    How can I get it to display only the persons name

    Thanks in advance



  • Hi,

    The drop down filter is not quite working for me.  It seems like it only work when the page is a postback.  I can't get the default value to work.  When I first load the page, I don't see anything.  Then when I change the value of the dropdown, I see my item filtered correctly.

    Any idea?



  • Hi John,

    This post was really helpful - thank-you! I'm having a problem though, when the column I use in my drop-down list is a calculated column. My formula in the calculated column is: =TEXT(Date,"yyyy") so that I can see the Year of an entry from the Date column. However, when I preview the page in my browser, the years show up in the drop-down box as 'string;#2008' etc. Do you have ideas about how I can get it to just display the years properly?

    Thanks, Krystie

  • Has anyone figured out how to get the select all feature to work yet?

Page 5 of 12 (167 items) «34567»
Leave a Comment
  • Please add 3 and 7 and type the answer here:
  • Post