views:

40

answers:

2

A form is populated from a list and I need it filtered. I have a table with a date column and would like to display only the rows of the required month. For this I have used XPath filtering:

[((ddwrt:FormatDateTime(string(@MyDateColumn) ,1061 ,'MM'))=02)]

This gives me the results for February, all ok. Now what I am trying to achieve is to make the month selectable with a drop-down list:

<asp:DropDownList runat="server" id="DropDownList1">
        <asp:ListItem Selected="True" Value="01">January
        </asp:ListItem>
        <asp:ListItem Value="02">February</asp:ListItem>
    </asp:DropDownList>

The drop-down can also be a regular html select if it would help, no difference there. But how can I retrieve the chosen value of the select with XPath?

Trying to achieve this with XPath because SharePoint's "regular" filtering only allows filtering by full date, not by day, month or year separately.

A: 

If you have this XML document (the ASP text in the question isn't well-formed XML):

<select>
    <option selected="selected" value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="6">June</option>
    <option value="7">July</option>
    <option value="8">August</option>
    <option value="9">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option>
</select>

and selection $m, then this XPath expression:

/*/*[@value=$m]/text()

selects the wanted text-node that corresponds to $m.

The XPath expression above reads:

Select all text nodes that are children of any element whose value attribute is equal to the value of $m and that is a child of the top element of the document.

For example:

/*/*[@value=7]/text()

selects the text node

"July"

and

/*/*[.=$v]/@value

for example:

/*/*[.='July']/@value

selects the value attribute, equal to 7.

Dimitre Novatchev
Sorry if I didn't explain myself clearly, but I want to get the value of such a list that you posted, not set it. I need for filtering SharePoint List data.
Indrek
@Indrek: Sorry, The XPath expression *is* getting you the value: "July" for 7. Can you explain?
Dimitre Novatchev
I need to get the value of the selected list in an Xpath filter (I'm using the select to control which data is shown).
Indrek
So, you need to get 7 for July? The reverse?
Dimitre Novatchev
Yes (and 'Yes' once more for min comment length).
Indrek
@Indrek: I have edited my answer -- now you have it both ways.
Dimitre Novatchev
A: 

Ah great, my long answer and connection error! Being shorter this time:

I just wanted to filter form/table rows by month. For this I created an ASP.NET Control DropDownList:

<asp:DropDownList runat="server" id="DropDownList1" AutoPostBack="True">
        <asp:ListItem Value="01">January</asp:ListItem>
        <asp:ListItem Value="02">February</asp:ListItem>
        <asp:ListItem Value="03">March</asp:ListItem>

    </asp:DropDownList>

Now to filter my DataFormWebPart by the date column, I first created a parameter. A parameter can be easily created when choosing Filter for the form and under the Value column choosing Create new parameter.... Just created a parameter MyParameter from Controls:DropDownList1. Now this parameter can be used in XPath filtering:

[((ddwrt:FormatDateTime(string(@MyDateColumn) ,1061 ,'MM'))=$MyParameter)] 
Indrek