gpt4 book ai didi

c# - 如何在 c# asp.net 中删除和添加 css 类到 gridview 内的特定文本框?

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:53 25 4
gpt4 key购买 nike

请告诉我如何删除 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";

关于c# - 如何在 c# asp.net 中删除和添加 css 类到 gridview 内的特定文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20600704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com