Solved

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

Posted on 2006-07-19
3
317 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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