Tuesday, September 13, 2011

ListView with HyperLink column


Here's my first try to work with a ListView. Before I had never used this control, but in my situation it became very handy. The results on my picture.
Here's a source code

<asp:ListView runat="server" ID="ListView1"
DataSourceID="SqlDataSource1">
<LayoutTemplate>
<table runat="server" id="table1" cellpadding="0" cellspacing="0" border="0">
<tr runat="server" id="itemPlaceholder" ></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr1" runat="server">
<td id="Td1" runat="server" valign="top">
<asp:Label ID="Year" runat="server" Text='<%#Eval("year") %>'/>
</td>
<td width="30px"> </td>
<td id="Td2" runat="server">
<asp:Label ID="Title" runat="server"
Text='<%#Eval("title") %>' style="font-weight:bold;" />
</td>
</tr>
<tr id="Tr2" runat="server">
<td> </td>
<td width="30px"> </td>
<td id="Td3" runat="server">
<asp:Label ID="Author" runat="server"
Text='<%#Eval("author") %>'/>
</td>
</tr>
<tr id="Tr3" runat="server">
<td> </td>
<td width="30px"> </td>
<td id="Td4" runat="server">
<asp:Label ID="Journal" runat="server"
Text='<%#Eval("journal") %>'/>
</td>
</tr>
<tr id="Tr4" runat="server">
<td> </td>
<td width="30px"> </td>
<td id="Td5" runat="server">
<asp:HyperLink ID="Link" Target="_blank"
NavigateUrl='<%# Eval("link") %>'
runat="server">Link to the article</asp:HyperLink>
</td>
</tr>
</ItemTemplate>
</asp:ListView>

Most interesting part is a HyperLink column. This feature became very useful for my project and works just fine.

No comments:

Post a Comment