“selectedData” XPO DevExpress to ListView

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using WebDevExp.Entity.apotek2;

public partial class Account_View : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            Session session = new Session();
            XpoDataSource1.Session = session;

            SelectedData result = XpoDataSource1.Session.ExecuteQuery("Select id,username FROM apotek2.dbo.account");
            XPDataView dv = new XPDataView();
            dv.AddProperty("id", typeof(int));
            dv.AddProperty("username", typeof(string));
            dv.LoadData(result);

            ListViewAccount.DataSource = dv;
            ListViewAccount.DataBind();
        }
    }
}

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="View.aspx.cs" Inherits="Account_View" %>

<%@ Register Assembly="DevExpress.Xpo.v13.1.Web, Version=13.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Xpo" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <table>
        <asp:ListView ID="ListViewAccount" runat="server">
            <ItemTemplate>
                <tr>
                    <td><%# Eval("id") %></td>
                    <td><%# Eval("username") %></td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
        </table>
        <dx:XpoDataSource ID="XpoDataSource1" runat="server"></dx:XpoDataSource>
    </form>
</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: