在 SharePoint 中使用 XPath 检索控件/选择值

发布于 2024-09-26 18:42:11 字数 639 浏览 2 评论 0原文

表单是从列表中填充的,我需要对其进行过滤。我有一个带有日期列的表,并且想仅显示所需月份的行。为此,我使用了 XPath 过滤:

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

这给了我二月份的结果,一切正常。现在我想要实现的是通过下拉列表选择月份:

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

如果有帮助的话,下拉列表也可以是常规的 html 选择,没有区别。但是如何使用 XPath 检索 select 的选定值?

尝试使用 XPath 来实现此目的,因为 SharePoint 的“常规”过滤仅允许按完整日期进行过滤,而不能单独按日、月或年进行过滤。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一城柳絮吹成雪 2024-10-03 18:42:11

如果您有此 XML 文档(问题中的 ASP 文本不是格式良好的 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>

并选择 $m,则此 XPath 表达式:

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

选择与$m对应的所需文本节点

上面的 XPath 表达式如下:

选择作为 value 属性等于 $m 的值的任何元素的子元素的所有文本节点,并且该元素是文档的顶部元素。

例如:

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

选择文本节点

“July”

例如

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

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

选择 value 属性,等于7

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.

心安伴我暖 2024-10-03 18:42:11

啊太棒了,我的长答案和连接错误!这次更短:

我只想按月过滤表单/表格行。为此,我创建了一个 ASP.NET 控件 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>

现在,为了按日期列过滤我的 DataFormWebPart,我首先创建了一个参数。当为表单选择“过滤器”并在“值”列下选择“创建新参数...”时,可以轻松创建参数。刚刚从 Controls:DropDownList1 创建了一个参数 MyParameter。现在这个参数可以用在XPath过滤中:

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

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)] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文