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

标签 asp.net vb.net

我的 .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/

相关文章:

vb.net - YouTube 签名解密以及 VB.Net 的工作示例

c# - 在 Linq 组中查找最大和最小 DateTime

javascript - 控件 id 正确呈现但仍然出现 javascript 错误

c# - 如何使用 csom 将 SharePoint 2013 列表数据绑定(bind)到 asp.net 的 gridview 中的下拉列表

asp.net - 替代 IIS for Windows 运行 ASP.NET

database - 与 EF 配合良好且易于部署的独立数据库选项?

c# - 在 Vista+ 上双击 .NET Label 控件将其文本复制到剪贴板?

c# - BackgroundWorker 和 System.Threading.Thread 之间的区别

.net - 将附件添加到.NET电子邮件

c# - 将 AddPooledDbContextFactory 与 AspNetCore.Identity 结合使用