Home
Products
Forums
Help
Publish Article
Go Freelance

Formatting Grid View - Change appearance of rows

Downloads

If you are seeing this section and do not see download links, this means that you are not logged into our site. If you already are a member, click on the login link and login into site and come back to this page for downloading the control files. If you are not a member, click on registration link to become a Winista member and download the control for free.

In DataGrid and GridView controls there is a property that lets you specify specify style for alternate rows. For DataGrid this property is AlternatingItemStyle and for GridView it is AlternatingRowStyle. For one of my reports the requirement was slightly different. The client wanted to alter behavior of every third row in the view. Thats where GirdView's RowCreated event came in very handy. You simply subscribe to this event and your event handler gets called for every row creation. In this event you can check the properties of Row getting created and you can alter the rendering property. Following code shows how I was able to set the background color of every third row in GridView.
protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
        if (((e.Row.RowIndex+1) % 3) == 0)
        {
            e.Row.BackColor = System.Drawing.Color.Snow;
        }
     }
}
Go Freelance
Home     About us     Contact us    Copyright    Privacy Policy    Return Policy    Advertisers
Copyright © Netomatix