动态绑定服务器控件属性值

后台CS代码:

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.DataBind();
        }
    }

前台HTML代码:

<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack ="true">
           <asp:ListItem Value ="images/001.jpg" Selected ="True" >图1</asp:ListItem>
           <asp:ListItem Value ="images/002.jpg" >图2</asp:ListItem>
           <asp:ListItem Value ="images/003.jpg" >图3</asp:ListItem>
        
        </asp:DropDownList>
        
        <asp:Image ID="Image1" runat="server" 
         ImageUrl ="<%# DropDownList1.SelectedItem.Value  %>" />
    </div>
    </form>
</body>

通过选择DropDownList,可以实现动态绑定图片控件的图片路径。

posted on 2011-03-10 20:44  云起的自学笔记  阅读(315)  评论(0编辑  收藏  举报

导航