ASP-的DropDownList codeBehind图片 [英] ASP-DropDownList CodeBehind images

查看:179
本文介绍了ASP-的DropDownList codeBehind图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所想要的是我的DropDownList是特殊的。 (

All I ever wanted is my DropDownList to be special. :(

我可以写只是名字,但不会像intresting。于是,我就添加图像,像这样:

I can write just names, but that won't be as intresting. So I tried to add images, like so:

// Somewhere in the code...
ListItem item = new ListItem();
item.Value = // something
item.Text = "<img src=\"" + <AnImagePathIGetFromTheDatabase> + "\">";
<MyDropDownlist>.Items.Add(item);

然而,邪恶的东西自动转义在列表中的文本,就像这样:

However the evil thing escapes the text in a list automatically, like so:

&放大器; LT; IMG src=&quot;https://41.media.tumblr.com/bcb96f4a4c46a1001118ee216d7abacf/tumblr_mgfhbngsDl1r58qimo1_500.png&quot;&gt;

所以我得到的文本,而不是图像。我该如何克服这个问题?

So I get text instead of an image. How can I overcome this?

修改:用约什的解决方案,我必须在我检查选择元件的情况,我也得到了以下内容:

EDIT: Using Lajos' solution, I've got to a situation where I inspect the selection element, And I get the following :

<img src="http://i.somethingawful.com/u/robtg/Fiesta/f05.jpg" alt="monster" height="42" width="42">

这是pretty多我一直在寻找。可悲的是,在页面的源代码,我得到如下:

Which is pretty much what I was looking for. Sadly, in the page source, I get the following:

<option value="MeaninglessImp" class="imageconverter">http://i.somethingawful.com/u/robtg/Fiesta/f05.jpg</option>

该列表本身就说明了2个空单元格。检查员说,照片已缩减为0x0。

The list itself shows 2 empty cells. The inspector says the pictures have been scaled down to 0x0.

小提琴:这里

为什么会发生呢?

推荐答案

您可以设置文本包含源,直到加载页面不显示它们。您可以实现一个JavaScript库,它取代SRC文字与列表中的图像。这应该解决的问题。

You can set the Text to contain the source and not show them until the page is loaded. You can implement a Javascript library which replaces src text with images in your list. That should solve the problem.

// Somewhere in the code...
ListItem item = new ListItem();
item.Value = // something
item.Text = <AnImagePathIGetFromTheDatabase>;
listItem.Attributes.Add("class", "imageconverter");
<MyDropDownlist>.Items.Add(item);

和在Javascript中你需要这样的:

And in Javascript you need something like:

$(function() {
    $(".imageconverter").each(function() {
        $(this).html('<img src="' + $(this).text() + '">');
    });
});

这篇关于ASP-的DropDownList codeBehind图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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