asp.net listview绑定到对象

时间:2011-08-16 22:04:32

标签: asp.net

关于wcf服务

public class Response
{
    public string ID { get; internal set; }
    public string Data { get; set; }
    public List<Message> Messages { get; set; }
}

public class Message
{
    public DateTime DateTime { get; set; }
    public string Message { get; set; }
    public string ProcessName { get; set; }

    public Message()
    {
        DateTime = DateTime.Now;
        Message = "";
        ProcessName = "";
    }
}

asp.net

protected void Page_Load(object sender, EventArgs e)
{
    BasicHttpBinding binding = new BasicHttpBinding();
    binding.MaxReceivedMessageSize = int.MaxValue;
    binding.MaxBufferSize = int.MaxValue;

    EndpointAddress endpoint = new EndpointAddress(new Uri(System.Configuration.ConfigurationManager.AppSettings["wcfserviceURL"]));
    Wcfservice.wcfserviceClient wcfservice = new Wcfservice.wcfserviceClient(binding, endpoint);

    Wcfservice.Response response = wcfservice.ReturnResponse();

    //I need to bind the response.Messages to a listview. It should display data in 3 columns DateTime, Message and ProcessName
}

我使用了数据源向导,它创建了以下内容。但我不知道接下来要做什么来显示数据

<asp:ListView ID="ListView1" runat="server" DataSourceID="LinqDataSource1">
</asp:ListView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
    ContextTypeName="Wcfservice.Response" EntityTypeName="" 
    TableName="Messages">
</asp:LinqDataSource>

1 个答案:

答案 0 :(得分:0)

尝试将此添加到您正在尝试绑定ListView的页面加载中:

LinqDataSource1.DataBind();