Solved

Change color of row based on bound YES/No column.

Posted on 2006-07-19
3
318 Views
Last Modified: 2012-06-21
I have a YES/NO Field bound to a column in a gridview.  If that column is false, I would like to change color of row, otherwise leave as is.
0
Comment
Question by:Break40
3 Comments
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 250 total points
ID: 17138338
Hi Break40,

In your ItemDataBound event:

If e.item.itemtype=ItemType.ListItem or e.item.itemtype= itemtype.alternatingitem then
    if e.item.cells(0).text = "False" Then
        e.item.backcolor=color.red
    End if
End if

Tim Cottee
0
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 250 total points
ID: 17138378
Hi Break40,
 you can do it in rowdatabound event by following way

void gvSSLookup_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            string lblYesNovalue = e.Row.Cells[1].Text;
            if (lblYesNovalue == "Yes")
                e.Row.BackColor = "color1"
            else
                e.Row.BackColor = "color2"

          }
    }
Regards,
NetSwap
0
 

Author Comment

by:Break40
ID: 17139140
I found another posting and came up with following that works when added to the "gvWorkweek2.RowDataBound" event.  

I also added a line ".Cells(0).Visible = False" that hides first column, which  has the edit and delete tags.  But when I do this the header text for the column is still there.  How can I hide that as well?  Here is my code.


With e.Row
            Dim rv As Data.DataRow
            If .RowType = DataControlRowType.DataRow Then
                rv = CType(.DataItem, Data.DataRowView).Row
                ' Change color
                If Not IsDBNull(rv("Approved")) Then
                    If rv("Approved") = "True" Then
                        .BackColor = Drawing.Color.Red
                        .Cells(0).Visible = False
                    Else

                    End If
                End If
            End If
        End With
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question