c# - 从下拉列表中选择后如何更改图像url

标签 c# asp.net html

您好,我有一个下拉列表和 ID,就像在选择四个选项之一以在代码隐藏中设置 Image2 的 imageurl 时一样?

最佳答案

一个例子。在您的标记中:

< <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" />

在您的代码隐藏中:

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

}

关于c# - 从下拉列表中选择后如何更改图像url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5532248/

相关文章:

javascript - IE10始终显示缓存的PDF文档

html - Logo 未显示在每个页面上

html - textarea和提交按钮的关系

c# - 如何以编程方式从 Google 驱动器中的 "share with me"中删除文件

c# - 如何从列表框 C# 中删除选定的项目

c# - iTextSharp - C# - 使字体加粗并加下划线

javascript - 如何使用 javascript 在 asp 中重置从 regularExpressionValidator 生成的此范围的文本

c# - 当我点击 Modal pop Extender 中的按钮时,更新进度 GIF 图像无法显示

javascript - 透明背景颜色内的图像不受影响

c# - 读取第一个和最后一个字母后解析c#中的字符串