[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change Gridview Color Row Dynamically

Posted on 2011-03-03
4
Medium Priority
?
637 Views
Last Modified: 2012-05-11
Can someone share a code or the steps to color the cells of a gridview control , based on the status of a table in sql server .

Thanks
0
Comment
Question by:TonyReba
[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
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35026890
You need to handle the RowDataBound event of your gridview. You can then interrogate the data being bound to the current row and act accordingly.

For example:
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView row = e.Row.DataItem as DataRowView;
                if (row["SomeColumn"].ToString() == "SomeValue")
                {
                    e.Row.Cells[0].Attributes.Add("class", "highlighted");
                }
            }
        }

Open in new window

0
 
LVL 9

Author Comment

by:TonyReba
ID: 35027040
class", "highlighted

does that comes from the style sheet?

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 35027103
Yes. So if you had something like the following in your style sheet then that would get applied to the cell (or row if you apply it at that level):
.highlighted { background-color: yellow; }

Open in new window

0
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 35027237
thanks will try it !
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Suggested Courses

656 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