Friday, 8 November 2019

RowDataBound Event In GridView In ASP.NET



RowDataBound Event In GridView In ASP.NET


  1. <form id="form1" runat="server">  
  2.     <div>  
  3.         <asp:GridView ID="GridView1" runat="server" CellPadding="6" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">  
  4.             <Columns>  
  5.                 <asp:BoundField DataField="Id" HeaderText="Id"/>  
  6.                 <asp:BoundField DataField="Name" HeaderText="Name"/>  
  7.                 <asp:BoundField DataField="City" HeaderText="City"/>  
  8.                 <asp:BoundField DataField="Salary" HeaderText="Salary"/>  
  9.             </Columns>  
  10.         </asp:GridView>  
  11.     </div>  
  12. </form>  


  1.  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
  2.     {  
  3.         //Checking the RowType of the Row  
  4.         if(e.Row.RowType==DataControlRowType.DataRow)  
  5.         {  
  6.             //If Salary is less than 10000 than set the row Background Color to Cyan  
  7.             if(Convert.ToInt32(e.Row.Cells[3].Text)<10000)  
  8.             {  
  9.                 e.Row.BackColor = Color.Cyan;  
  10.             }  
  11.         }  
  12.     } 

No comments:

Post a Comment