Wednesday, January 28, 2009

How ASP.NET drop down controls Filter the Data View in SharePoint Designer?

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...

Place your page into design view
Click Task panes :: Data Source Library
Click the data source called Categories
Click to Insert Data Source Control
If prompted, click “Yes” to display the control
Place insertion point below this control
Click Insert :: ASP.NET Controls > Drop Down List
Click the Smart Panel :: Choose Data Source...
Choose the Data Source (for example, SPListDataSource1)
Tell it to display "CategoryName" (or the field that contains your category name)
Make its value "CategoryName"
Click OK
Click to select the dropdownlist control
Click the Smart Panel :: AutoPostBack == True

For getting a default value like "Please select a item..." ?
1. Select the control
2. click on Task Panes > Tag Properties
3. change the AppendDataBoundItem to be True
4. Click the Smart Panel > Edit Items
5. click "Add"
6. type "Please select a item..." for the Text property
7. Click "OK"

Drag and drop the Products list onto a page to create a Data View
Clck the Smart Panel :: Edit Columns to add and remove the columns you want to display
Click Data View :: Filter
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
Click OK
Click OK again
Save the page
Preview in the browser
Make a change to the DropDownList control

2 comments:

Chris Britton said...

Great...Is it possible with just SPD to filter for None or All.

I have it working with two filter rules for Category from Drop Down and location from drop down.

I might just want to filter say by room, can i do this without code? Or can I add code simply ?

aparna john said...

Hi,If there is a lot of Web Design Cochin content on your website , would be to use a search box. Finally, the navigation link should be highlighted to help see where they are.Thanks.....