为变色控件指定变量 [英] Assign a variable to backcolor control

查看:65
本文介绍了为变色控件指定变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对gridview进行条件格式化。



Hi, I am doing a conditional formatting on my gridview.

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;
}
}
}



因此,所有不正确的输入都会以红色突出显示。

现在,我想在文本框中删除所有不正确的输入,但我不知道该怎么做。



如果我加上这两个,



string error = tileInput;

TextBoxTileID.Text = tileInput.Replace(错误,);



文本框中的整个输入被空格替换。



因此可以将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!

推荐答案

您可以将该TextBox的ToolTip属性设置为red,之后如果将ToolTip设为red则执行以下操作检查TextBoxes你想做什么。
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.


这篇关于为变色控件指定变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆