请告诉我如何删除CssClass并将其添加到gridview内的特定文本框?
这是我尝试过的,但它不会更改文本框的css
我的.aspx页面中的CSS是:
<style type="text/css">
.erroramount
{
border:3px solid red
}
</style>
在我的按钮中,单击此处是我的gridview循环代码,其中取决于我想更改文本框边框颜色的条件;
var result = (from f in dtCloned.AsEnumerable()
group f by f.Field<string>("AssetDescription") into g
select
new
{
AssetDescription = g.Key,
TotalAmount = g.Sum(r => r.Field<double?>("Amount"))
});
foreach (var aAsset in result.AsEnumerable())
{
if (aAsset.TotalAmount < 0)
{
foreach (GridViewRow arow in GridProjectDetails.Rows)
{
string AssetDescription = ((TextBox)arow.FindControl("TextAssetDescription")).Text;
if (AssetDescription == aAsset.AssetDescription)
{
((TextBox)arow.FindControl("TextAmount")).CssClass = "erroramount";
}
}
}
}
最佳答案
除非代码无法访问或找不到控件,否则您的声明应该起作用。如果找不到控件,它将引发异常。还有另一种设置类的方法:
((TextBox)arow.FindControl("TextAmount")).Attributes["class"] = "erroramount";