将服务器图像嵌入HTML [英] Embedding server image in HTML

查看:106
本文介绍了将服务器图像嵌入HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态创建了一个HTML表,然后我想在该表的单元格中嵌入一个服务器映像,我这样做是-

I created an HTML table dynamically.Then I wanted to embed a server image in the cell of that table.I did so as-

HtmlTableCell c = new HtmlTableCell();
Image img = new Image();
img.ImageUrl = Server.MapPath("Images/red.jpg");
c.Controls.Add(img); 


但是当我执行此操作时,图像没有出现.
我在这里想念什么吗?

请提出建议.

在此先感谢!!
[edit]添加了代码块"Ingore HTML ..>"选项已禁用-OriginalGriff [/edit]


But when I execute this, the image is not appearing.
Am I missing something over here?

Please suggest.

Thanks in advance !!
[edit]Code block addded, "Ingore HTML..>" option disabled - OriginalGriff[/edit]

推荐答案

尝试使用以下代码,希望它可以工作.
Try using the following code, hope it will work.
HtmlTable tab = new HtmlTable();
tab.Border = 1;
tab.BorderColor = "#cccccc";
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell c = new HtmlTableCell();
Image img = new Image();
img.ImageUrl=Page.ResolveClientUrl("~/Images/red.jpg");
img.Style.Add("width", "300px;");
img.Style.Add("height", "400px");
c.Controls.Add(img);
c.Style.Add("width", "300px;");
c.Style.Add("height", "400px;");
tr.Cells.Add(c);
tab.Rows.Add(tr);
form1.Controls.Add(tab);



如果我误解了您的问题,请随时纠正我.希望以上信息对您有所帮助.如果您还有其他顾虑,请告诉我.

如果这确实对您有帮助,请不要忘记投票并接受答案.



If i misunderstand your question, please feel free to correct me.I hope the above information will be helpful. If you have more concerns, please let me know.

If this would be really helpful to you then don''t forgot to Vote and Make Answer as Accepted.


是的.


哦,你想要更多细节吗?
Yes.


Oh, you want more details?
HtmlTableCell c = new HtmlTableCell();

创建表单元格的新实例:thumbsup:

Creates a new instance of a table cell :thumbsup:

Image img = new Image();

创建一个新的图片控件. :thumbsup:

Creates a new image control. :thumbsup:

img.ImageUrl = Server.MapPath("Images/red.jpg");

将Image控件指向一个图像文件:thumbsup:

Points the Image control at an image file :thumbsup:

c.Controls.Add(img);

将图像添加到表格"单元格.
然后不使用表格单元格尝试显示它....:thumbsdown:

Adds the Image to the Table cell.:thumbsup:

And then does nothing with the table cell to try and display it....:thumbsdown:


将表格单元格添加到表格行中,然后将表格行添加到表格单元格中?通过创建一个新的HtmlTableCell,它不会附加到它需要的任何父对象上.
我问是因为您的代码段并不表示您已经成功完成了该部分.
Did you add the table cell to the table row and then the table row to the table cell? By creating a new HtmlTableCell, it isn''t attached to any of the parent objects that it needs to be.
I ask because your snippet doesn''t indicate that you have done that part successfully.


这篇关于将服务器图像嵌入HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆