0

I am not really an expert of .Net, I am trying to consume a Java webService which returns a XML code as a String (because it was easier for me to return a String rather than return an XML).

At the moment I am using an XML file (test.xml) in App_Data folder and my gridview works as follows:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" 
            DataSourceID="XmlDataSource1" ForeColor="#333333" GridLines="None" 
            Width="547px">
            <AlternatingRowStyle BackColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />
        </asp:GridView>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
            DataFile="~/App_Data/test.xml"></asp:XmlDataSource>

What I have to do when I get the returned String from the Web Service?

1) Should I save the string as an XML? In this case how can I save the String in the "App_Data" folder?

2) Is there any other solution instead of saving the String?

Many thanks

1 Answer 1

1

You need to set the Data Property of your data source

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.data.aspx

I guess you will also need to remove the DataFile property set statically in you aspx file.

protected void Page_Load(object sender, EventArgs e)
{
    XmlDataSource1.Data = ResultOfMyWebService;
}
Sign up to request clarification or add additional context in comments.

3 Comments

mm I don't think I did it properly: <asp:XmlDataSource ID="XmlDataSource1" runat="server" > <Data>String</Data> </asp:XmlDataSource>
[PersistenceModeAttribute(PersistenceMode.InnerProperty)] [TypeConverterAttribute("System.ComponentModel.MultilineStringConverter,System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public virtual string Data { get; set; }
Well... no. You have to do it in the code behind. Something like XmlDataSource1.Data = WebServiceResult. You could give the data in the constructor of the page and then set it in the Page_Load... depends on when your call to webservice is made

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.