Load Image to asp:Image : Image « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <asp:Label ID="Label1" runat="server" Height="32px" Text="Image to display" Width="176px"></asp:Label>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="112px">
                <asp:ListItem>A</asp:ListItem>
                <asp:ListItem>B</asp:ListItem>
            </asp:DropDownList>
            <div>
                <asp:Button ID="Button1" runat="server" Text="Select Image" /></div>
        </div>
        <div>
            <asp:Image ID="Image1" 
                       runat="server" 
                       AlternateText="Image" 
                       Height="128px" 
                       ToolTip="Image"
                       Width="208px" /></div>
    
    </div>
    </form>
</body>
</html>


File: Default.aspx.vb


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case DropDownList1.SelectedIndex
            Case 0
                Image1.ImageUrl = "http://www.java2s.com/style/logo.png"
            Case 1
                Image1.ImageUrl = "http://www.java2s.com/style/logo.png"

        End Select

    End Sub
End Class








3.7.Image
3.7.1.Important properties of Image control
3.7.2.Load Image to asp:Image
3.7.3.Set ImageUrl and AlternateText for asp:Image (VB.net)
3.7.4.Image alignment