我正在建立一个简单的页面,该页面仅显示XML文件的内容,并允许用户按关键字进行过滤。
我是一个认真的.NET newb,但是我已经设置了XmlDataSource:
<asp:XmlDataSource ID="RSSFeedDataSource" runat="server" DataFile="test.xml"
XPath="/rss/channel/item[contains(title,"theKeyword")]"></asp:XmlDataSource>
因此,我想允许用户键入关键字并根据该关键字更改数据源。
我想我会从文本输入中对该关键字进行回发,抓取该关键字并以某种方式插入XPath表达式中...
在这一点上,我将寻求简化,但这是最简单的方法吗?
最佳答案
通过后面的代码和按钮回发来获取它的方法
ASP页:
<asp:TextBox id="txtKeyword" runat="server" />
<asp:Button id="btnKeyword" OnClick="btnKeyword_Click" runat="server" />
后面的代码:
public void btnKeyword_Click(Object sender, EventArgs e)
{
// Assuming C#
// Retrieve the keyword from the text box
string keyword = txtKeyword.Text
// Next step would be to modify the XPath of your XmlDataSource
RSSFeedDataSource.XPath = "/rss/channel/item[contains(title," + keyword + ")]"
}
关于.net - .NET:可以根据URL参数更改XPath()表达式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/437298/