开发者

Calls to successive calls on repeater with XML datasource is not binding new data

I have the following Page_Load function...

protected void Page_Load(object sender, EventArgs e)
{
  XmlDataSource1.Data = GetXmlFromFile(Request.QueryString["开发者_高级运维file"]);
  XmlDataSource1.DataBind();

  Repeater1.DataBind();                      
}

The page in which this Page_Load resides is called by a parent page. Each time this Page_Load gets called the value of "file" in the query string will be different. So each time I will be receiving the XML contents from a different file which are inserted into the XmlDataSource and then bound against by the Repeater. Getting the XML data from the file works great but when I bind against the repeater that only works the first time through Page_Load. Each time after that when this code is executed the same results from the first XML file are displayed in the repeater.

What am I missing here. How can I get the XML data to be bound against the repeater on each page load instead of just the first one?


Tried creating a new XmlDataSource on each load?

protected void Page_Load(object sender, EventArgs e)
{
  XmlDataSource source = new XmlDataSource();
  source.ID = "MyDS";
  source.Data = GetXmlFromFile(Request.QueryString["file"]);
  source.DataBind();

  Repeater1.DataSource = source;
  Repeater1.DataBind();                      
}


I tried to duplicate the problem with a simple implementation that follows your main concept.

Code behind:

protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["file"] != null)
    {
        XmlDataSource XmlDataSource1 = new XmlDataSource();
        XmlDataSource1.DataFile = "~/App_Data/" + Request.QueryString["file"];
        Repeater1.DataSource = XmlDataSource1;
        Repeater1.DataBind();
    }
}

Markup:

<asp:Repeater runat="server" ID="Repeater1" DataSourceID="XmlDataSource1">
    <ItemTemplate>
        <asp:Label runat="server" ID="lbl" Text='<%# Eval("Name") %>'></asp:Label>
    </ItemTemplate>
</asp:Repeater>

This works when I browse to "Default.aspx?file=West.xml" where west.xml is an xml file in my App_Data folder. When I enter another existing xml file in the query string, it performs as expected. It's quick n' dirty, but maybe it will give you some idea when comparing it against your existing code.


On further investigation turns out the problem is a caching flag which is set to default true on XmlDataSource's. Other data source types like SqlDataSource do not have this flag enabled.

This is more fully outlined in the following article http://geekswithblogs.net/ranganh/archive/2006/04/28/76638.aspx

Upon disabling the caching feature everything works as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜