Archive for July, 2015

How to highlight the selected rows in Repeater using Jquery


In this article I am going to explain how to highlight the selected row in Repeater control using Jquery.  At runtime Repeater control will render as table we will be manipulating this table structure to access each row and then use the css to highlight the row.


You need to add the necessary JQuery files to your page prior to use this plugin. In this example I have used the online JQuery CDN files available. If you don’t want to use the online available cdn file then you can manually add the jquery files to your solution. I have explained the steps here in detail.


We will use the below css to hightlight the rows in gridview.

<style type="text/css">
            background-color: #9999FF;

Jquery Code:             

Below Jquery function will remove the css from all other rows except the selected row

 <script src=""></script>
    $(function () {
         $(".trclass").click(function () {


   <asp:Repeater runat="server" ID="Repeater1">
                <table width="500px" border="1px">
                    <tr style="background-color: #fb7700">
                <tr class="trclass">
                        <asp:Label ID="lblValue1" runat="server" Text='<%# Eval("val1") %>'></asp:Label>
                        <asp:Label ID="lblValue2" runat="server" Text='<%# Eval("val2") %>'></asp:Label>

Below code is to populate dummy data, you dont need this code if you are populating the repeater from database in code behind.


  protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                DataTable table1 = new DataTable();
                table1.Rows.Add("Value1", "Message1");
                table1.Rows.Add("Value2", "Message2");
                table1.Rows.Add("Value3", "Message3");
                table1.Rows.Add("Value4", "Message4");
                table1.Rows.Add("Value5", "Message5");
                table1.Rows.Add("Value6", "Message6");
                table1.Rows.Add("Value7", "Message7");
                Repeater1.DataSource = table1;



, , , , ,

Leave a comment