0

我有一个绑定到 XmlDataSource 的树视图。我想在这个 XmlDataSource 的正文中搜索关键字并重新绑定树视图。找到描述它的这篇文章,但我的搜索没有返回任何内容。

我的 xml 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<articles name="articles">
  <folder name="Folder1">
    <article name="art1">
      <body>This is body 1</body>
      <createuser>someuser</createuser>
      <createddate>28/02/2013 06:24:34</createddate>
    </article>
    <article name="art2">
      <body>&lt;p&gt; this is body 2</body>
      <createuser>someuser2</createuser>
      <createddate>28/02/2013 06:30:36</createddate>
    </article>
   </folder>
</articles>

并且我使用的代码在按钮上单击如下,并输入“this”作为关键字:

protected void btnSearch_Click(object sender, EventArgs e)
{
    XmlArticle.XPath = "/articles/folder/article[body='" + txbSearch.Text + "']";
    //XmlArticle.XPath = "/articles/folder[article/body='" + txbSearch.Text + "']"; //tried this too
    tvCMSArts.DataBind();
}
4

1 回答 1

1

尝试这个:

XmlArticle.XPath = "/articles/folder/article[contains(body,'" + txbSearch.Text + "')]";
于 2013-08-16T10:42:33.683 回答