简体   繁体   中英

C# Use returned web service String as XML Data source in Grid View

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

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM