ASP.NET:如何为在 C# 代码隐藏中生成的表应用 CSS 类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/929240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:25:39  来源:igfitidea点击:

ASP.NET: How to apply CSS class for a Table generated in C# codebehind

c#asp.net

提问by Shyju

I have an ASP.NET page and I am generating an HTML table in my server side code (codebehind file )as follows.

我有一个 ASP.NET 页面,我正在我的服务器端代码(代码隐藏文件)中生成一个 HTML 表,如下所示。

 HtmlTable iTblCart = new HtmlTable();
 HtmlTableRow iRowHeader = new HtmlTableRow();
 HtmlTableCell iCellHead1 = new HtmlTableCell();
 iCellHead1.InnerText= "Item";
 iRowHeader.Cells.Add(iCellHead1);
 iTblCart.Rows.Add(iCartRow);
 pnlPhoneCart.Controls.Add(iTblCart);  //appending to a panel

I want to apply a CSS class to this table.I could not find such a property from the intellisense.Am i missing anything ? Can anyone guide me how to go ahead ?

我想将 CSS 类应用于此表。我无法从智能感知中找到这样的属性。我错过了什么吗?谁能指导我如何继续?

采纳答案by Shyju

Yes I got the answer.Here it is

是的,我得到了答案。在这里

iTblCart.Attributes.Add("Class", "clsTradeInCart");

and clsTradeInCart is my CSS class name

clsTradeInCart 是我的 CSS 类名