【问题标题】:How to populate data to GridControl from Web Service?如何从 Web 服务向 GridControl 填充数据?
【发布时间】:2012-08-27 09:43:46
【问题描述】:

我在向 GridControl 添加行/单元格值时遇到问题。 我使用 Web 服务作为数据源。 我的 Web 服务功能运行完美并返回 xml 类型的值 例如

<User>
<UserID>000015</UserID>
<UserGroup>MR</UserGroup>
<UserName>ARIF SETYOWARDOYO</UserName>
<IsActive>1</IsActive>
</User>

我将 Web 服务作为“添加服务”添加到我的项目中。 而且,我的 BindingSource 代码:

userBindingSource.DataSource = typeof(DXWindowsApplication1.WebService.User);

我已将 BindingSource 附加到 GridControl,它会自动创建 4 列,分别是 UserID、UserGroup、UserName 和 IsActive。
但他们的行中没有数据。如果我在下面运行此脚本,它将运行并返回值..

WebService.MyWebServiceWs = new WebService.MyWebServiceWs ();
WebService.User[] user = Ws.GetUserDetails();
string userId = user[0].UserID.ToString();
string userGroup = user[0].UserGroup.ToString();
string userName = user[0].UserName.ToString();
string isActive = user[0].IsActive.ToString();//int isActive = user[0].IsActive.Value;



所以我的问题是,接下来我该怎么做才能将这个 WebService 数据检索到 GridControl 中?
任何参考将不胜感激...
谢谢 :)
干杯..

【问题讨论】:

    标签: c# winforms devexpress bindingsource gridcontrol


    【解决方案1】:

    我在没有 web 服务的情况下从 web 读取 xml,并使用以下代码填充我的表:

    // needed variable
    private DataSet ds;
    //read xml and poupolate table
     System.Xml.XmlDataDocument xmlDatadoc = new System.Xml.XmlDataDocument();
    
                    xmlDatadoc.DataSet.ReadXml("http://your link to xml");
                    ds = xmlDatadoc.DataSet;
    
    
    
                    datagridviwe1.DataSource = ds.DefaultViewManager;
                    datagridviwe1.DataMember = "User";
    

    但是您需要对我们的 xml 文件进行一些更改,这是一个示例:

    <User UserID="000015" UserGroup="MR" UserName="ARIF SETYOWARDOYO" IsActive="1" />
    <User UserID="000016" UserGroup="MRS" UserName="LADY LAYON" IsActive="0" />
    

    这个包含所有值的填充表,用于个性化显示的内容,您需要将源与您的 xsd 架构绑定并编辑表生成。

    【讨论】:

    • 您好,devilkkw,感谢您的回复。这真的激励我前进。但是,在这种情况下我仍然有问题,因为我必须使用 web 服务,但我不知道如何更改该 xml 格式。
    • 我认为要使用您的网络服务,您需要为所有接收到的数据创建数组,然后使用它来生成数据网格(方法 foreach)。我没有尝试过这种方法,我没有帮助你有示例代码。对不起。
    猜你喜欢
    • 2011-07-16
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 2013-08-12
    • 2016-08-13
    • 1970-01-01
    相关资源
    最近更新 更多