如何从DropDownList中选择后更改图片网址 [英] how to change imageurl after selection from dropdownlist

查看:79
本文介绍了如何从DropDownList中选择后更改图片网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个DropDownList和身份证一样在选择的四个选项之一来设置IMAGE2的图片网址在code后面?

Hi I have a dropdownlist and id like upon selecting one of the four choices to set the imageurl of Image2 in code behind?

推荐答案

这是例子。在您的标记:

An example. In your markup:

< <asp:DropDownList ID="TestDropDownList" runat="server" 
    onselectedindexchanged="TestDropDownList_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Value="http://url.com/image1.png" Text="Option 1"></asp:ListItem>
<asp:ListItem Value="http://url.com/image2.png" Text="Option 2"></asp:ListItem>
<asp:ListItem Value="http://url.com/image3.png" Text="Option 3"></asp:ListItem>
<asp:ListItem Value="http://url.com/image4.png" Text="Option 4"></asp:ListItem>
</asp:DropDownList>
<asp:Image ID="TestImage" ImageUrl="" runat="server" />

在您的code-背后:

In your code-behind:

protected void TestDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
        Image i = this.TestImage;
        i.ImageUrl = ((DropDownList)sender).SelectedValue;

}

这篇关于如何从DropDownList中选择后更改图片网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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