本文介绍了如何在asp.net mvc3中使用dropdownllist选定的值显示和隐藏div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
dropdownlistfor(model => model.ddlstatevalue)
例如ddlstatevalue包含apple,ball,cat
如果我选择苹果,那么必须显示apic图片
如果我选择了球,那么必须有球的图像,依此类推
我该怎么做?
dropdownlistfor(model=>model.ddlstatevalue)
for eg ddlstatevalue contains apple,ball,cat
if i select apple then there must be display of pic of aapple
if i select ball then there must be image of ball and so on
how can i do this ?
推荐答案
<div>
<asp:DropDownList ID="ddlstateval" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlstateval_SelectedIndexChanged">
<asp:ListItem Text="Apple" Value="Apple"></asp:ListItem>
<asp:ListItem Text="Cat" Value="Cat"></asp:ListItem>
<asp:ListItem Text="Ball" Value="Ball"></asp:ListItem>
</asp:DropDownList>
</div>
<div>
<asp:Image ID="imgViewSelected" runat="server" ImageUrl="~/Images/Apple.jpg" />
</div>
后面的代码
code behind
protected void ddlstateval_SelectedIndexChanged(object sender, EventArgs e)
{
imgViewSelected.ImageUrl = "~/Images/"+ddlstateval.SelectedValue.ToString() + ".jpg/";
}
这篇关于如何在asp.net mvc3中使用dropdownllist选定的值显示和隐藏div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!