Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET-使用字符串更改标签颜色和浓度_C#_Asp.net_Colors_Label - Fatal编程技术网

C# ASP.NET-使用字符串更改标签颜色和浓度

C# ASP.NET-使用字符串更改标签颜色和浓度,c#,asp.net,colors,label,C#,Asp.net,Colors,Label,我创建了一个标签,并将其文本颜色设置为红色。我使用前景色,但他不工作:( 这是我的用户界面: Label reqF = new Label(); reqF.Text = "*"; reqF.ForeColor = System.Drawing.Color.Red; reqF.CssClass = "formvalidation"; reqF.Font.Size = 15; // 15px Table

我创建了一个标签,并将其文本颜色设置为红色。我使用前景色,但他不工作:(

这是我的用户界面:

        Label reqF = new Label();
        reqF.Text = "*";
        reqF.ForeColor = System.Drawing.Color.Red;
        reqF.CssClass = "formvalidation";
        reqF.Font.Size = 15; // 15px
        TableHeaderCell header1 = new TableHeaderCell();
        header1.Text = "Destination" + reqF.Text;  <----------- My label
        tRow0.Cells.Add(header1);

这是我的标签代码:

        Label reqF = new Label();
        reqF.Text = "*";
        reqF.ForeColor = System.Drawing.Color.Red;
        reqF.CssClass = "formvalidation";
        reqF.Font.Size = 15; // 15px
        TableHeaderCell header1 = new TableHeaderCell();
        header1.Text = "Destination" + reqF.Text;  <----------- My label
        tRow0.Cells.Add(header1);
这是我的字符串代码:

        Label reqF = new Label();
        reqF.Text = "*";
        reqF.ForeColor = System.Drawing.Color.Red;
        reqF.CssClass = "formvalidation";
        reqF.Font.Size = 15; // 15px
        TableHeaderCell header1 = new TableHeaderCell();
        header1.Text = "Destination" + reqF.Text;  <----------- My label
        tRow0.Cells.Add(header1);
TableHeaderCell header1=新的TableHeaderCell();
该行中的header1.Text=“Destination”+需求文本;

header1.Text = "Destination" + reqF.Text; 
只将文本(*)添加到目标,而不是打开样式的完整div

最简单(更快)的方法是直接在线添加样式,如下所示:

header1.Text = "Destination <span style=\"color=red\">*</span>" ;
header1.Text=“目的地*”;

您只使用控件的文本,而不是整个控件的样式。您的代码实际上应该是这样的:

TableHeaderCell header1 = new TableHeaderCell();
LiteralControl literal = new LiteralControl();
literal.Text = "Destination";
header1.Controls.Add(literal);
header1.Controls.Add(reqF);
tRow0.Cells.Add(header1);

请注意,此处使用
Literal
控件插入
Description
字符串,然后插入带有
*
的整个标签。

我们在输出中实际查看的是哪个控件?如果是
TableHeaderCell
,您在哪里修改其颜色?@Gohyu尝试此
header1.Text=“目的地”+“*”