【问题标题】:CssClass won't workCssClass 不起作用
【发布时间】:2014-12-29 10:05:00
【问题描述】:

我正在构建一个表格并动态放置乘法按钮。问题是我还给了他们一个 CSS 类来使用,但它不起作用,我不知道为什么?!

这里是代码

protected void Page_Load(object sender, EventArgs e)
{
    int rowNum = 4;
    int cellNum = 10;
    int idcell = 1;
    int idrow = 1;

    for (int i = 0; i < rowNum; i++)
    {
        TableRow aNewRow = new TableRow();
        for (int j = 0; j < cellNum; j++)
        {
            TableCell aNewCell = new TableCell();
            Button aNewButton = new Button();

            aNewButton.Click += new System.EventHandler(this.Button_Click_First_Row);
            aNewButton.ID = "R" + idrow + "B" + idcell;
            aNewButton.Text = "Boka";
            aNewButton.CssClass = "dynamicbuttons";

            aNewCell.Controls.Add(aNewButton);
            aNewRow.Cells.Add(aNewCell);
            idcell++;
        }
        Table1.Rows.Add(aNewRow);
        idrow++;
    }
}

还有我的 CSS 类

.dynamicbuttons {
    background-color:green;
    width:105px;
}

我不知道为什么它不起作用。

【问题讨论】:

  • 是输出html中的css类吗?在浏览器中右键显示超文本
  • 不,不是。根本不显示。

标签: c# css class button dynamic


【解决方案1】:

我尝试了您的代码,并且在输出 html 中获得了 css 类,因此可能是您环境中的其他东西导致了问题。

我的测试标记:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        .dynamicbuttons {
            background-color:green;
            width:105px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Table ID="Table1" runat="server"></asp:Table>
    </div>
    </form>
</body>
</html>

以及后面的代码:

public partial class TableForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int rowNum = 4;
        int cellNum = 10;
        int idcell = 1;
        int idrow = 1;

        for (int i = 0; i < rowNum; i++)
        {
            TableRow aNewRow = new TableRow();
            for (int j = 0; j < cellNum; j++)
            {
                TableCell aNewCell = new TableCell();
                Button aNewButton = new Button();

                //aNewButton.Click += new System.EventHandler(this.Button_Click_First_Row);
                aNewButton.ID = "R" + idrow + "B" + idcell;
                aNewButton.Text = "Boka";
                aNewButton.CssClass = "dynamicbuttons";

                aNewCell.Controls.Add(aNewButton);
                aNewRow.Cells.Add(aNewCell);
                idcell++;
            }
            Table1.Rows.Add(aNewRow);
            idrow++;
        }
    }
}

【讨论】:

  • 是的,我不知道为什么它不起作用。我创建了一个新的 CSS 表并将其链接到我的 CssClass,它就像一个魅力......
猜你喜欢
  • 2018-05-08
  • 1970-01-01
  • 2011-03-08
  • 1970-01-01
  • 2017-08-23
  • 2012-02-24
  • 2016-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多