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.

-John

  • Preview error:

    I can manage in SHD steps 1-21 according to the description and it shows data in design mode but when I try to Preview in the browser  it writes:

    An unexpected error has occurred.

    Troubleshoot issues with Windows SharePoint Services.

    Where could be a problem?

    Other aspx pages (NewForm.aspx etc.) are ok.

  • Robert, to get MOSS errors edit the web.config:

    Set CallStack to true in SafeMode <SafeMode MaxControls="200" CallStack="true"...

    Turn off custom errors <customErrors mode="Off" />

    Note: it is recommended you only do this on test/dev systems

  • Hi,

    I got a question. I would like to filter my DataView with a Text box, which I got it working (kind of). However the text should be case sensitive, in other words if I query in something that does not have the same case, i don't get any results.

    Any help would be appreciated.

    Thanks,

    Shankar.

  • Shankar, can you share your text box solution with me/us?

    I have the following - but its not working:

    <ParameterBinding Name="Param1" Location="Control(TextBox1,Text)" DefaultValue=""/>

    When I provide a DefaultValue, SPD displays the correct filter result. But on the web page no results show up.

    This is my text box control:

    <asp:TextBox runat="server" id="TextBox1" AutoPostBack="True"></asp:TextBox>

    The only control I get to work is the DropDownList.

    Thanks!

  • ok, it looks like it needed a IISRESET or so. the above solution is working with textbox.

    Jan

  • Is there a way to list only distinct values within a DropDownList using a SP list for the Datasource?

  • Hi there,

    i have a problem. I tried to filter a data view with a drop down list. Ive done like stated above but it wont work. I dont understand why. Has somebody a tip for me?

  • <xsl:param name="FilePath" />

    <xsl:param name="Param1">Vista</xsl:param>

    ...

    <xsl:variable name="Rows" select="/table/data/row[contains(normalize-space(col [ 6 ] ), $Param1)]"/>

    Here some code from me. If the default value of the drop down list is vista the filter works but whatever i select in the drop down list the page reloads and the data view is filtered with vista.

  • Hi,

    if i use only SharePoint Lists like in this article it works. I use a xml data source and i think this is the problem. Somebody an idea?

  • Is there any way to make the filter optional?  Meaning is there any way to allow the user to see all rows in the list?

  • Hi,

    look @ July 28, 2007 5:24 PM

    1. Smart Panel -> Filter

    2. Click "Add XSLT Filtering..." and then the Edit button

    3. Add the above @CategoryName = $Param1 or $Param1 = '(All)' between the brackets.

    You can define 'All' as default. Works fine for me!

    -----------------------------------------------------

    My Problem still remains unsolved. How can i filter XML datasources? With Lists its no Problem but XML data sources it wont work. Only the default filter shows up.

    Hope some DEV has an idea.

    bye Richard

  • Hello there,

    I've this problem that I just can't seem to resolve:

    I put a control with an sqldatasource just like this:

    <asp:SqlDataSource runat="server" id="Interlocuteur" ConnectionString="blabla" ProviderName="System.Data.Odbc" SelectCommand="SELECT * FROM Annuary WHERE  Annuary.SocietyName=@newparameter">

    <SelectParameters>

    <asp:controlparameter Name="newparameter" ControlID="TextBox1" Type="String" DefaultValue="k"/>

    </SelectParameters>

    </asp:SqlDataSource>

    but I get an error on my page, it doesn't seem to know the value of my Control

  • Hi my sqlDataSource with the code like this:

    <asp:SqlDataSource...  SelectCommand="SELECT * FROM [States] where [Country] = @Country">

    <SelectParameters>

    <asp:controlparameter PropertyName="SelectedValue" Name="Country" ControlID="ddlCountry" />

    </SelectParameters>

    </asp:SqlDataSource>

    doesn' t seem to work with Sharepoint, the control doesn't have any value

  • Hi,

    I'm trying to filter a Data View, which i have place in a DispForm, with a sharepoint control  (SharePoint:ListItemProperty). I have created the paramenter with this control, but it doesn't works. Why? Any idea?

    thanks,

  • I have a SQLDataSource that I need to pass the current user name to in order to filter the data.  Can someone suggest a solution?

Page 4 of 12 (167 items) «23456»
Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post