Solved

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

Posted on 2006-07-19
3
314 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now