Tuesday, June 29, 2010

ListView in ASP.NET

HAHA, apprantly, i do not know how to use list view, as it works much different as compared to datalist and it fixes the problem i have with data list (where if i use a table, then it becomes table in a table problem)

Anyways, here is a Nice tutorial from Scott Gu,
http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx

AND anyways to use ListView, after adding
  <asp:ListView ID="lvTaskUpdate" runat="server">

1) Add <LayoutTemplate> with Placeholder

e.g

 <LayoutTemplate>
          <table cellpadding="6" width="80%" border="1" ID="tbl1" runat="server">
            <tr id="Tr1" runat="server" style="background-color: #bbbbbb">
              <th id="Th1" runat="server">ID</th>
              <th id="Th2" runat="server">From:</th>
              <th id="Th3" runat="server">Comments</th>
              <th id="Th4" runat="server">Date Posted</th>
              <th id="Th5" runat="server">Options</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
</LayoutTemplate>


2) Add <ItemTemplate> and we are done.
e.g
<ItemTemplate>
 <tr id="Tr2" runat="server">
  <td><asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("id") %>' /></td>
  <td><%#  Eval("creator") %></td>
  <td><asp:Label ID="NameLabel" runat="server" Text='<%# Eval("description") %>' /></td>
  <td><asp:Label ID="Label1" runat="server" Text='<%# Eval("dateCreated") %>' /></td>
  <td><%#editUpdateFunction()%></td>
</tr>
</ItemTemplate>
</asp:ListView>

And We are done!

No comments: