C# asp.net web form Textbox string problem

I'm new to C# and ASP.NET so thanks in advance for help with this.

Im writing a simple web application that will display a DataGrid, and color the entire row based on the value of one column in the rows.
The column in my DB is called "Status" and the possible values will be "Requested", "In Transit" or "Received" with each value rendering a different color.

When debugging, it is showing my string value as "" even though there is data in the field.

My code is below:
using System;
using System.Data;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace NameOfMyApp
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = e.Row.DataItem as DataRowView;
                if (drv["Status"].ToString().Equals("Requested"))
                    { 
                        e.Row.BackColor = System.Drawing.Color.Tomato;
                    }
                else if (drv["Status"].ToString().Equals("In Transit"))
                    {
                        e.Row.BackColor = System.Drawing.Color.Yellow;
                    }
                else
                    {
                        e.Row.BackColor = System.Drawing.Color.Lime;
                    }
            }
        }
    }
}

Open in new window


Its currently coloring all of my rows Green because of the empty value being returned.

Appreciate any help!
hhnetworksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

plusone3055Commented:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = e.Row.DataItem as DataRowView;
               if (drv["Status"].ToString() == "Requested")
                    {
                        e.Row.BackColor = System.Drawing.Color.Tomato;
                    }
                else if (drv["Status"].ToString()  == "In Transit")
                    {
                        e.Row.BackColor = System.Drawing.Color.Yellow;
                    }
                else
                    {
                        e.Row.BackColor = System.Drawing.Color.Lime;
                    }
0
plusone3055Commented:
if the value is showing ""  then you are not placing the correct value into your code
have you done a F10 Run to cursor to see if its catching that value ???
0
hhnetworksAuthor Commented:
Ive tried the code both ways (with the '==' and 'Equals') in the IF statement; and yes I have run to cursor and the string value is coming up empty, even though there's valid data in that column.

This was my reason for posting the question.

Thanks!
0
edwardqCommented:
I do it the following way.


But I tried it both my way and plusone way and get the same results.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                  
               string strStatus = (string)DataBinder.Eval(e.Row.DataItem, "Status");

              if (strStatus.ToLower() == "requested")
                    {
                        e.Row.BackColor = System.Drawing.Color.Tomato;
                    }
                else if ((strStatus.ToLower()   == "in transit")
                    {
                        e.Row.BackColor = System.Drawing.Color.Yellow;
                    }
                else
                    {
                        e.Row.BackColor = System.Drawing.Color.Lime;
                    }

 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hhnetworksAuthor Commented:
Thanks Edward!!

You code worked perfectly!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.