Click here to Skip to main content
15,886,766 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I am doing a conditional formatting on my gridview.

C#
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
      
{
string tileInput = Convert.ToString(e.Row.Cells[1].Text);//This retrieved from user input (TextBox) and now its output in gridview, at row 1

string tileDB = Convert.ToString(e.Row.Cells[0].Text); //This is retrieved from database and now its output in gridview, at row 0

if (tileInput == tileDB)
{
e.Row.BackColor = Color.White;
}

else 
{
e.Row.BackColor = Color.Red;
}
}
}

As a result, all the incorrect input will become red-highlighted.
Now, I would like to delete all incorrect input in text box but I have no idea how to do it.

if i add in these 2,

string error = tileInput;
TextBoxTileID.Text = tileInput.Replace(error, "");

whole input in text box is replaced by empty space.

So is it possible to assign "e.Row.BackColor = Color.Red" to a variable or boolean so that I can detect that this cell is red-colored, so that I can replace the incorrect input with space in text box?

Your help is much appreciated. Thank you!
Posted
Comments
ramyajaya 2-Sep-15 16:02pm    
After setting the color you can set the value for the cell as blank as e.Row.Cells [0].Text="";
Member 11765602 2-Sep-15 20:55pm    
Hi, thanks for answering but I'm not attempt to delete the data at gridview, instead, I want to delete the input at textbox based on the color of its cell.

1 solution

You can set the ToolTip property for that TextBox as "red" and after that you check for the TextBoxes if having ToolTip as "red" do whatever you want to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900