With reference of this article i have used the ListView design
How to use table layout in ListView control in ASP.Net
And from this i have set the selected index of ListView Item using jQuery
http://jsfiddle.net/9pmcA/26/
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
tr.selected
{
background-color: red;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".lvCustomers tr").click(function () {
if ($(this).find('th').length == 0) {
$(".lvCustomers tr").each(function () {
$(this).removeClass("selected");
});
$(this).addClass("selected");
}
});
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="lvCustomers" runat="server" GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table class="lvCustomers" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
Country
</th>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<%# Eval("Id") %>
</td>
<td>
<%# Eval("Name") %>
</td>
<td>
<%# Eval("Country") %>
</td>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
Namespace
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
lvCustomers.DataSource = dt;
lvCustomers.DataBind();
}
}
}
Screenshot