?
Solved

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

Posted on 2006-07-19
3
Medium Priority
?
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 750 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 750 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

800 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