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

Thursday, January 29, 2015

RowDataBound event in a GridView to highlight the rows or cells

RowDataBound event in Asp.net GridView to highlight the rows or cells:



In this Post i want describe about few topic  in rowdatabound event which is available in asp.net 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">
            <Columns>
                <asp:TemplateField HeaderText="Userprofile">
                    <ItemTemplate>
                     
                        <asp:Label ID="lblText" runat="server" Text='<%# Eval("Price") %>'
></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>


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.


Asp.net Related Other Post :




No comments:

Post a Comment