ListView vs Gridview

by rbellantoni 4/7/2010 8:43:00 AM

Some people may be wondering what is the difference is between a ListView and a GridView. In my opinion, the ListView is a much better tool in regards to displaying and manipulating data. With the ListView you use templates to design the different views. The first template is the with this template you can dictate where you want your datarows to show up and how you want your data laid out here is an example:

<asp:ListView ID="lvProducerPools" runat="server" onitemdatabound="lvProducerPools_ItemDataBound" onitemcommand="lvProducerPools_ItemCommand" DataKeyNames="PoolID,Locked_flag">
<LayoutTemplate>
<div style="float:left;width: 1000px;overflow-x:auto;overflow-y:hidden;padding-top:5px; padding-bottom:15px;">
<table cellpadding="0" cellspacing="0" style="table-layout:fixed;height:18px;font-size:10pt;">
<tr style="height:18px;" id="itemPlaceholder" runat="server" />
</table>
</div>
</LayoutTemplate>
<ItemTemplate>
<td id="poolLInk" style="width:175px;height:18px;background-color:#cdcdcd;border-right:1px gray groove; padding: 2px;" runat="server">
<asp:LinkButton ID="lnkLoadPool" runat="server"> <%# Eval("PoolName")%></asp:LinkButton>
<asp:Image ToolTip="Deals in this allocation have been locked" ID="imgLock" runat="server" Visible='<%# Eval("Locked_flag")%>' ImageUrl="~/images/lock.gif" />
<asp:Label BorderColor="#8c9bad" BackColor="White" Font-Bold="true" BorderStyle="Double" BorderWidth="2px" ForeColor="Black" Font-Size="10px" ID="lblImbalance" runat="server" Text='<%# Eval("TLBalance")%>' >
</td>
</ItemTemplate>
<EmptyDataTemplate>
<table>
<tr>
<td id="poolLInk" style="background-color:#cdcdcd;border-right:1px gray groove; padding: 4px;" runat="server">
<b>NO PRODUCTION POINTS !!!
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>

The ID for "itemPlaceHolder" is not by accident, this is the identifier row where your itemtemplate rows will be bound. The advantage to this is that you have FULL control of how the html is rendered from your datasource. Whereas in a gridview your stuck with the table column design of the layout. Additionally you can use the datapager control inside of the template to enable paging, which does not work with the Gridview Control.

 

Tags:

.NET | ASP.NET AJAX | BlogEngine.NET | VB.NET

Comments

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  October 2018  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Recent comments

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018

Sign in