programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Thursday, January 29, 2015

RowDataBound event in a GridView to highlight the rows or cells

RowDataBound event in GridView to highlight the rows or cells:

In this Post i want describe about few topic  in rowdatabound event which is available in gridview control and these tips will provide the solution for all possible requirements when working with rowdatabound event in gridview control.

How to use a RowDataBound event in a GridView:

how to use a RowDataBound event in a GridView to highlight the rows or cells in ASP.NET. This example is helpful in situations where you need to highlight the GridView rows or cells based on a specific condition.

First we take an ASP.NET GRID Control:

<asp:GridView ID="GRDSample" runat="server" AutoGenerateColumns="false" OnRowDataBound="GRDSample_RowDataBound">
                <asp:TemplateField HeaderText="Userprofile">
                        <asp:Label ID="lblText" runat="server" Text='<%# Eval("Price") %>'

In this we take  lable control in grid control.

Know we want to create event by C# code on .aspx.cs page

protected void GRDSample_RowDataBound(object sender, GridViewRowEventArgs e)
            DataRowView drview = e.Row.DataItem as DataRowView;
            if (e.Row.RowType == DataControlRowType.DataRow)
                Label lblText       = e.Row.FindControl("lblText") as Label;
                if (Convert.ToInt32(lblText.Text) > 100)
                    e.Row.ForeColor = System.Drawing.Color.Black;
                    e.Row.Font.Bold = true;
                    e.Row.BackColor = System.Drawing.Color.Brown; 

If you want to change the gridview row color change on mouse over and mouse out then write the below code in rowdatabound event. Related Other Post :

No comments:

Post a Comment