How to not display the a row based on a condition.
-
The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M){ e.Row.ForeColor = System.Drawing.Color.Red; } else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M) { e.Row.ForeColor = System.Drawing.Color.Orange; } else //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M)) { e.Row.Visible = false; }
-
The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M){ e.Row.ForeColor = System.Drawing.Color.Red; } else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M) { e.Row.ForeColor = System.Drawing.Color.Orange; } else //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M)) { e.Row.Visible = false; }
If you are using a DataTable, you might want to try setting the RowFilter property of the DefaultView.
-
The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M){ e.Row.ForeColor = System.Drawing.Color.Red; } else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M) { e.Row.ForeColor = System.Drawing.Color.Orange; } else //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M)) { e.Row.Visible = false; }
If that row is not required, then filter it while getting the data from your data source. So you can avoid all these at code level in C#.
-
The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M){ e.Row.ForeColor = System.Drawing.Color.Red; } else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M) { e.Row.ForeColor = System.Drawing.Color.Orange; } else //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M)) { e.Row.Visible = false; }
Norris Chappell wrote:
Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015
Which one's
ActualFTE
in these, and what's with theLabel lst
?You have just been Sharapova'd.
-
The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M){ e.Row.ForeColor = System.Drawing.Color.Red; } else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M) { e.Row.ForeColor = System.Drawing.Color.Orange; } else //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M)) { e.Row.Visible = false; }
Norris Chappell wrote:
Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015
Which one's
ActualFTE
among these, and what's with theLabel lst
?You have just been Sharapova'd.
-
If that row is not required, then filter it while getting the data from your data source. So you can avoid all these at code level in C#.
I changed my sql but it now showing the first row which is < .075 as black not yellow. The rest of the rows are correct. Bair James S 176.0000 1.0000 128.0000 0.7300 04/01/2015
-
If you are using a DataTable, you might want to try setting the RowFilter property of the DefaultView.
Can you Please explain what that means? I'm now getting all of the rows I want but the very first record is not Yellow which is less than .075. All o the remaining rows are correct.
-
The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M){ e.Row.ForeColor = System.Drawing.Color.Red; } else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M) { e.Row.ForeColor = System.Drawing.Color.Orange; } else //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M)) { e.Row.Visible = false; }
Sorry for the delayed reply, I don't check the inbox linked with this account too often. I think you might have resolved this issue already, but - ;) If the ActualFTE is 0.7300, as you have mentioned in the email, the row should have been highlighted in Orange color? If that's "not" the case, are you sure you still have the
else if
condition< .75M
in place and it's really not< .075
by any chance (from what you have mentioned in your original post)? Also, can you check what you are getting fromConvert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"))
using immediate window/quick watch and a debug point?You have just been Sharapova'd.
-
Sorry for the delayed reply, I don't check the inbox linked with this account too often. I think you might have resolved this issue already, but - ;) If the ActualFTE is 0.7300, as you have mentioned in the email, the row should have been highlighted in Orange color? If that's "not" the case, are you sure you still have the
else if
condition< .75M
in place and it's really not< .075
by any chance (from what you have mentioned in your original post)? Also, can you check what you are getting fromConvert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"))
using immediate window/quick watch and a debug point?You have just been Sharapova'd.
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
// Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
// if (Convert.ToDecimal(last.Text) > 1.25M)
{
e.Row.ForeColor = System.Drawing.Color.Orange;
}
// else if (Convert.ToDecimal(last.Text) < .75M)
else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)
{
e.Row.ForeColor = System.Drawing.Color.Red;
}The conditions are working properly. It is the fact that the very first record is not changing to Orange even though it is < .075
-
protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
{
// Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
// if (Convert.ToDecimal(last.Text) > 1.25M)
{
e.Row.ForeColor = System.Drawing.Color.Orange;
}
// else if (Convert.ToDecimal(last.Text) < .75M)
else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)
{
e.Row.ForeColor = System.Drawing.Color.Red;
}The conditions are working properly. It is the fact that the very first record is not changing to Orange even though it is < .075
There's no need to loop over all the rows - the
RowDataBound
event will fire for each row. Try changing your code to:protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
if (actualFTE < .75M)
{
e.Row.ForeColor = System.Drawing.Color.Orange;
}
else if (actualFTE > 1.25M)
{
e.Row.ForeColor = System.Drawing.Color.Red;
}
}If it still doesn't work, check the HTML source to see what's rendered for the first row. You might want to add the ActualFTE to the row as a
data-
attribute, to make sure the value is what you're expecting:decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
e.Row.Attributes.Add("data-actual-fte", actualFTE.ToString());
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
There's no need to loop over all the rows - the
RowDataBound
event will fire for each row. Try changing your code to:protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
{
decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
if (actualFTE < .75M)
{
e.Row.ForeColor = System.Drawing.Color.Orange;
}
else if (actualFTE > 1.25M)
{
e.Row.ForeColor = System.Drawing.Color.Red;
}
}If it still doesn't work, check the HTML source to see what's rendered for the first row. You might want to add the ActualFTE to the row as a
data-
attribute, to make sure the value is what you're expecting:decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
e.Row.Attributes.Add("data-actual-fte", actualFTE.ToString());
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks. That worked. Is now doing what they want.