gpt4 book ai didi

asp.net - 在asp.net中动态更改表格单元格背景颜色

转载 作者:行者123 更新时间:2023-12-02 17:46:18 25 4
gpt4 key购买 nike

我的 .aspx 页面上有下表行:

<tr>
<td valign="bottom" style="width: 157px">Initial Requirements:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<asp:Repeater ID="Repeater11" runat="server" DataSourceID="ObjectDataSource1">

<ItemTemplate>
<td valign="bottom" id="ReqStatus" runat="server" style="background-color: Gray">
<%#ReqStatus(CType(CType(Container.DataItem, System.Data.DataRowView).Row, DataSet1.DataTable1Row))%>

</td>

</ItemTemplate>
</asp:Repeater>

</tr>

在后面的代码中我有这个函数:

Protected Function ReqStatus(ByVal Project As DataSet1.DataTable1Row) As String
'Dim ReqTableCell As TableCell
'ReqTableCell = form1.FindControl("ReqStatus")


' Check the status of the Development Completed
Dim rightNow As Date = Now()
Dim dateDifference As TimeSpan
If Not Project.IsNull("Requirements_Target") Then

Dim ReqTargetDate As Date = Project.Requirements_Target

If Project.IsNull("Req_Date") Then
dateDifference = ReqTargetDate.Subtract(rightNow)

If dateDifference.Days > 0 Then

If dateDifference.Days >= 60 Then
'ReqTableCell.BackColor = Drawing.Color.Green
Return "<strong><font color='green'>" & dateDifference.Days & "</font></strong>"
ElseIf dateDifference.Days > 30 And dateDifference.Days < 60 Then
'ReqTableCell.BackColor = Drawing.Color.Yellow
Return "<strong><font color='yellow'>" & dateDifference.Days & "</font></strong>"
Else

'ReqTableCell.BackColor = Drawing.Color.Red
Return "<strong><font color='red'>" & dateDifference.Days & "</font></strong>"
End If

Else
'ReqTableCell.BackColor = Drawing.Color.Red
Dim pastDue As Int16 = (dateDifference.Days * -1)
Return "<strong><font color='red'>" & pastDue & "</font></strong> days past"

End If
End If
Else

End If
End Function

我可以根据条件语句更改返回值的颜色,但无法找出更改表格单元格背景的正确语法。我的尝试被注释掉了。

如何正确声明表格单元格? Findcontrol一定不是正确的方法。

最佳答案

看看我的解决方案的截图:

TableRow tr = new TableRow();
TableCell tc = new TableCell { Text = "someText"};

tc.BackColor = ColorTranslator.FromHtml("#0000FF");
tc.ForeColor = ColorTranslator.FromHtml("#FFFFFF");
tc.Font.Bold = true;
tc.Font.Size = 16;

tr.Cells.Add(tc);
table.Rows.Add(tr);

完成此操作并控制所有语句后,您可以在网页中呈现表格。

关于asp.net - 在asp.net中动态更改表格单元格背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4018364/

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