If have a Xml-file with 3 entries
Country Name="Denmark" InternetTLD="dk"
Country Name="Holland" InternetTLD="nl"
Country Name="Greate britain" InternetTLD="uk"
In my web-page if have a textbox, gridview and xmlDataSource. When I don't specify anything in the textbox then all three countries are are loaded using a LINQ query into the xmlDataSource and then displayed in the gridview. But when I specify for example 'Denmark' in the textbox then I keep on seeing all 3 records whereas the count property of the LINQ query says 1 and the Data-property of the xmlDataSource shows only 1 country as well (Denmark) as it should be.
Problem is that the gridView doesn't seem to refresh the new data???
Here's my code:
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()
Why isn't the gridView refreshing?
thank you
Chris
Try turning off caching on the XmlDataSource
protected void Page_Load(object sender, EventArgs e)
{
xmlDsCountries.EnableCaching = false;
//...........the rest.............
}
精彩评论