gridview数据源问题

时间:2010-04-02 17:16:37

标签: c# asp.net web-services

我正在调用web服务,如下所示。我必须使用此web服务在gridview中显示名称,描述和URL。

using sdi.amiller_v_vista;

sdi.amiller_v_vista.DDCControl proxy1 = new sdi.amiller_v_vista.DDCControl();
sdi.amiller_v_vista.DDCReturnGetAll ret = proxy1.GetAllDDCs(x, y);

foreach (sdi.amiller_v_vista.DDCInfo2 di2 in ret.DDCs)
{
    GridView1.DataSource = I have to assign the di2 values(di2 is having name, description and url for each ddc) to gridview datasource

   //GridView1.DataSource = ret.DDCs[i] throws an error Data source is an invalid type.  It must be either an IListSource, IEnumerable, or IDataSource.

   GridView1.DataBind();
}

从WSDL元数据中我可以获得以下信息

public DDCReturnGetAll GetAllDDCs(Guid accountId, Guid authToken);

public class DDCReturnGetAll : DDCReturnBase
{
    public DDCReturnGetAll();
    public DDCInfo2[] DDCs { get; set; }
}

public class DDCInfo2
{
    public DDCInfo2();
    public BrandingType brandingType { get; set; }
    public string ChargebackName { get; set; }
    public string CollectorName { get; set; }
    public string Description { get; set; }
    public string URL { get; set; }
}

1 个答案:

答案 0 :(得分:0)

很难从你的样本中看出来,但是你可能想要做一些类似于替换它的事情:

foreach (sdi.amiller_v_vista.DDCInfo2 di2 in ret.DDCs) {
  GridView1.DataSource = I have to assign the di2 values to gridview datasource
  //GridView1.DataSource = ret.DDCs[i] throws an error Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
  GridView1.DataBind();
}

用这个:

  GridView1.DataSource = ret.DDCs
  GridView1.DataBind();