【问题标题】:How to change the border color of a single cell using dynamic table如何使用动态表格更改单个单元格的边框颜色
【发布时间】:2017-03-29 14:35:27
【问题描述】:

我正在创建一个动态表格,我想更改特定单元格的边框颜色,例如 (0,1)。我不知道如何访问特定单元格?有什么想法吗?

protected void cmdCreate_Click(object sender, EventArgs e)
{
    //clear the table
    tbl.Controls.Clear();

    int rows = Int32.Parse(txtRows.Text);
    int cols = Int32.Parse(txtCols.Text);

    for (int row = 0; row < rows; row++)
    {
        TableRow rowNew = new TableRow();

        tbl.Controls.Add(rowNew);

        tbl.Rows.AddAt(0, TableRow row);

        for (int col = 0; col < cols; col++)
        {
            //create a new tablecell object
            TableCell cellNew = new TableCell();

            cellNew.Text = "Example Cell (" + row.ToString() + "," + col.ToString() + ")";

            cellNew.BorderColor = System.Drawing.Color.Red;

            //     cellNew.Text += col.ToString() + ")";

            if (chkBorder.Checked)
            {
                cellNew.BorderStyle = BorderStyle.Inset;
                cellNew.BorderWidth = Unit.Pixel(1);
            }

            rowNew.Controls.Add(cellNew);
        }
    }
}

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您可以通过检查rowcol 来检查您所在的单元格。您还需要指定BorderStyle,而不仅仅是颜色。

    if (row == 0 && col == 1)
    {
        cellNew.BorderColor = System.Drawing.Color.Red;
        cellNew.BorderStyle = BorderStyle.Solid;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-11
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 2018-03-25
      相关资源
      最近更新 更多