1

I have a value for bind in lable.Text value is this below

value I want in lable this:

<ul class="Class">  <li><img width="440" height="600"/></li> </ul>

exactly same as it is

I'm calling value in lable like this

string Class = "pslides"; string width = "440"; string height = "600";  
lbl.Text = "<ul class=" + Class + ">  <li><img width=" + width + " 
height=" + height + "/></li> </ul>";

when I check the label.Text value then I will get result this

<ul class=Class>  <li><img width=440 height=600/></li> </ul>

but I want a label.text value like this

 lbl.Text = "<ul class="Class">  <li><img width="width" 
    height="height"/></li> </ul>";

I have to do this in with code in c# please give me solution how can I get the lable.text value like I want.

Thank You

4

2 回答 2

2

您只是在询问是否在值周围加上引号?你只需要在你的字符串中加上引号——你现在不这样做。您需要确保您正在转义引号,否则它将无法编译。

您可以在连接所有内容的位置添加引号:

string Class = "pslides"; string width = "440"; string height = "600";  
lbl.Text = "<ul class=\"" + Class + "\">  <li><img width=\"" + width + "\" height=\"" + height + "\"/></li> </ul>";

或者您可以将它们添加到您的字符串值,因为您已经将这些数字转换为字符串:

string Class = "\"pslides\""; string width = "\"440\""; string height = "\"600\"";  
lbl.Text = "<ul class=" + Class + ">  <li><img width=" + width + " height=" + height + "/></li> </ul>";

通常你会看到前者,我会说,而不是后者。

于 2013-07-22T17:31:03.870 回答
0

如果您只是询问如何转义引号,请使用单引号和双引号:

string cssClass = "pslides";
string width = "440";
string height = "600";

lbl.Text = "<ul class='" + cssClass + "'>" +
                    "<li>" +
                        "<img width='" + width + "' height='" + height + "'/>" +
                    "</li>" +
                "</ul>";

双引号用于将 C# 字符串括起来,而单引号用于将 HTML 属性括起来。希望这可以帮助。

如果您想要打印该 HTML,请不要使用label。您需要使用文字. 之后,将您的代码更改为:

string cssClass = "pslides";
string width = "440";
string height = "600";

Literal1.Text = "<ul class='" + cssClass + "'>" +
                    "<li>" +
                        "<img width='" + width + "' height='" + height + "'/>" +
                    "</li>" +
                "</ul>";
于 2013-07-22T18:05:37.877 回答