GridView不刷新LINQ到XML数据?
问题描述:
如果有一个XML的文件有3项GridView不刷新LINQ到XML数据?
国家名称= “丹麦” InternetTLD = “DK”
国家名称= “荷兰” InternetTLD = “NL”
国家名称=“马丽娟英国“InternetTLD =”英国“
在我的网页中,如果有一个文本框,gridview和xmlDataSource。 当我没有在文本框中指定任何内容时,所有三个国家都使用LINQ查询加载到xmlDataSource中,然后显示在gridview中。 但是,当我在文本框中指定例如“丹麦”时,我继续看到所有3条记录,而LINQ查询的count属性为1,xmlDataSource的Data-property只显示1个国家(丹麦)应该。
问题是gridView似乎没有刷新新数据?
这里是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
QueryXml();
} // Page_Load()
private void QueryXml()
{
XElement _countries = XElement.Load(Server.MapPath(COUNTRIES_XML));
IEnumerable<XElement> query = null;
// extract all countries
if (txtCountry.Text == "" || txtCountry.Text == "*")
{
query = from c in _countries.Elements()
select c;
}
else
{
// Extract all elements where Name has been specified
query = from c in _countries.Elements()
where c.Attribute("Name").Value.ToString().StartsWith(txtCountry.Text, StringComparison.CurrentCultureIgnoreCase)
select c;
}
// Set xml filtered string data source
xmlDsCountries.Data =
"<Countries>" +
string.Join("", query.Select(country => country.ToString())) +
"</Countries>";
// set the data source of the gridview
gdvwCountries.DataSource = xmlDsCountries;
// Show the data
gdvwCountries.DataBind();
lblMsg.Text = query.Count().ToString();
} // QueryXml()
为什么不是在GridView提神?
谢谢
克里斯
答
尝试上的XmlDataSource
protected void Page_Load(object sender, EventArgs e)
{
xmlDsCountries.EnableCaching = false;
//...........the rest.............
}
这工作好了与高速缓存禁用关闭缓存。 谢谢! – ChrisPeeters 2011-06-02 16:07:57
不是问题,请您将标记为正确的答案? – asawyer 2011-06-02 17:14:08