DotnetSparrow
DotnetSparrow

Reputation: 27996

Datagrid row color change based on data

I am working on asp.net 3.5 application. I have a datagrid. I want to change the row color based on the dataitem to which the row is bound. I know this can be easy done in gridview using rowdatabound event but this event it not available in Datagrid control. Please suggest me how to use it?

Regards, Asif Hameed

Upvotes: 1

Views: 2934

Answers (1)

Jupaol
Jupaol

Reputation: 21365

Have you tried:

    protected void grdSomething_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
            e.Item.BackColor = Color.AliceBlue;
    }

The tag

<asp:DataGrid runat="server" ID="grdSomething" AutoGenerateColumns="False"
    onitemdatabound="grdSomething_ItemDataBound">

The output:

enter image description here

Upvotes: 1

Related Questions