hhnetworks
asked on
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:
Its currently coloring all of my rows Green because of the empty value being returned.
Appreciate any help!
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;
}
}
}
}
}
Its currently coloring all of my rows Green because of the empty value being returned.
Appreciate any help!
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 ???
have you done a F10 Run to cursor to see if its catching that value ???
ASKER
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!
This was my reason for posting the question.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Edward!!
You code worked perfectly!
You code worked perfectly!
{
if (e.Row.RowType == DataControlRowType.DataRow
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (drv["Status"].ToString() == "Requested")
{
e.Row.BackColor = System.Drawing.Color.Tomat
}
else if (drv["Status"].ToString() == "In Transit")
{
e.Row.BackColor = System.Drawing.Color.Yello
}
else
{
e.Row.BackColor = System.Drawing.Color.Lime;
}