views:

231

answers:

0

I'm trying to use a GridView in a User Control with an XmlDataSource and the XmlDataSource will not be populated until runtime. I have another User Control that the user will use to pass in parameters for what data to display. The main Page that both these controls reside on collects the parameters from the Selector User Control and get the Xml from a Web Service, it then passes that information on to the GridView User Control for rendering. The problem is that it never renders, it's like it's invisible; there are no errors. Before showing the code understand that I can assure you that the Selector User Control works and the main Page properly gets the data and passes it to GridView User Control. I can verify that the XmlDataSource.Data property has the expected Xml Data in it and that it has the correct transform file. For whatever reason the control is never visible. What am I doing wrong?

UserControl:

<asp:GridView ID="gvData" runat="server" AllowPaging="True" AllowSorting="true">
</asp:GridView>
<asp:XmlDataSource ID="xdsData" runat="server" EnableCaching="false"></asp:XmlDataSource>

Code-behind:

public string XmlData 
{
    get 
    {
        object vs = this.ViewState[this.ClientID + "XmlData"];
        if (vs != null)
            return vs.ToString();

        return "<NoData />"; 
    }
    set
    {
        this.ViewState.Add(this.ClientID + "XmlData", value);
        BindXml();
    }
}

public string XmlTransformFile
{
    get
    {
        object vs = this.ViewState[this.ClientID + "XmlTransformFile"];
        if (vs != null)
            return vs.ToString();

        return string.Empty;
    }
    set
    {
        this.ViewState.Add(this.ClientID + "XmlTransformFile", value);
    }
}

protected void Page_Load(object sender, EventArgs e)
{
    BindXml();
}

protected void Page_PreRender(object sender, EventArgs e)
{
    BindXml();
}

private void BindXml()
{
    this.xdsData.TransformFile = XmlTransformFile;
    this.xdsData.Data = XmlData;
    this.xdsData.DataBind();
    this.gvData.DataSource = this.xdsData;
    this.gvData.DataBind();
}