ASP.NET Podcast Show #93 - ASP.NET ListView in Orcas Beta 1 - Video

Original URL: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2007/05/23/asp-net-podcast-show-93-asp-net-listview-in-orcas-beta-1-video.aspx

Subscribe

Download WMV

Download MP4

Show Notes:

  • ASP.NET ListView.
  • ListView as a Grid.
  • ListView as a Container of data.

Source Code:

ASPX Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListView.aspx.cs" Inherits="ListView" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ListView Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ListView ID="ListView1" runat="server" ItemContainerID="tblData">
    <layouttemplate>
        <table border="1">
            <tr>
                <th>Name</th>
            </tr>
            <tbody runat="server" id="tblData"></tbody>
        </table>
    </layouttemplate>
    <itemtemplate>
    <tr>
        <td><%# Eval("Name") %></td>
    </tr>
    </itemtemplate>
    </asp:ListView>
    <asp:ListView ID="ListView2" runat="server" ItemContainerID="ddlSelect">
    <LayoutTemplate>
        <select ID="ddlS" name="ddlS">
            <asp:PlaceHolder ID="ddlSelect" runat="server"></asp:PlaceHolder>
        </select>
    </LayoutTemplate>
    <ItemTemplate>
        <option><%# Eval("Name") %></option>
    </ItemTemplate>
    </asp:ListView>
    </div>
    </form>
</body>
</html>

Code Behind .cs file:

protected void Page_Load(object sender, EventArgs e)
{
    DataTable dtData = new DataTable();
    DataRow drData;
    dtData.Columns.Add( "Name", System.Type.GetType("System.String"));
    drData = dtData.NewRow();
    drData["Name"] = "Wally McClure";
    dtData.Rows.Add(drData);
    drData = dtData.NewRow();
    drData["Name"] = "Paul Glavich - my trusty sidekick";
    dtData.Rows.Add(drData);
    ListView1.DataSource = dtData;
    ListView1.DataBind();
    ListView2.DataSource = dtData;
    ListView2.DataBind();
}

PS.  Due to a snafu with my DNS Server, the site was inaccessible for a while today.  As a result, I took this post offline and put it back on once the server was back up and going. 

1 Comment

  • First of all, I think ListView is not a good name for this control. It's more like a different take on the repeater. There was one thing in the video that was not exactly clear and that kind of worries me; something about ListView replacing the Repeater. I have nothing against having an extra control, but there's no reason why the Repeater couldn't stay. The Repeater is one of those simple but powerful controls. There's no need to explain why you need a control inside a template and to have that hooked up with an ID (for ListView). It's just simple and the results are very easy to predict. Also not having control over the outputted html (see the span tag around the control) is very bad!

    Peter.

    P.S. maybe TemplatedRepeater would be a better name(?)

Comments have been disabled for this content.