如何在asp.net mvc3中使用dropdownllist选定的值显示和隐藏div? [英] how can we show and hide div using dropdownllist selected value in asp.net mvc3?

查看:109
本文介绍了如何在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 ?

推荐答案

检查此

http://www.w3schools.com/jquery/jquery_effects.asp [
Check this

http://www.w3schools.com/jquery/jquery_effects.asp[^]


如果您想使用简单的ASP.净代码,然后尝试以下操作.在此之前,将图像添加到您的解决方案中.希望这会有所帮助.

If you want to use simple asp.net code then try the below. before that add the images in your solution. Hope this helps.

<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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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