C# 如何使用动态表格更改单个单元格的边框颜色
我正在创建一个动态表,我想更改特定单元格的边框颜色,例如(0,1)。我无法确定如何访问特定单元格?有什么想法吗C# 如何使用动态表格更改单个单元格的边框颜色,c#,asp.net,C#,Asp.net,我正在创建一个动态表,我想更改特定单元格的边框颜色,例如(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);
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);
}
}
}
protectedvoid cmdCreate\u单击(对象发送方,事件参数e)
{
//收拾桌子
tbl.Controls.Clear();
int rows=Int32.Parse(txtRows.Text);
int cols=Int32.Parse(txtCols.Text);
对于(int row=0;row
您可以通过检查行
和列
来检查您所在的单元格。您还需要指定边框样式
,而不仅仅是颜色
if (row == 0 && col == 1)
{
cellNew.BorderColor = System.Drawing.Color.Red;
cellNew.BorderStyle = BorderStyle.Solid;
}