Showing posts with label DropDownList SelectedValue. Show all posts
Showing posts with label DropDownList SelectedValue. Show all posts

DropDownList Selected Item(Text) Values Display or Get Without Database Connection Using in Asp.Net C#

DropDownList Selected Item Values Display or Get Without Database Connection

DropDownList Selected Item Values Retrive or Display to Label Without Database Connection Using in Asp.Net C#.


                        DEMO



Download Coding



HTML CODING

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <table><tr><td
        <asp:Label ID="Label1" runat="server" Text="Select Country" Font-Size="Large"></asp:Label>
            </td><td>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Font-Size="Large" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem>Select Country</asp:ListItem>
            <asp:ListItem Value="NEW DELHI">INDIA</asp:ListItem>
            <asp:ListItem Value="TOKYO">JAPAN</asp:ListItem>
            <asp:ListItem Value="WASHINGTON">USA</asp:ListItem>
            <asp:ListItem Value="LONDON">UK</asp:ListItem>
        </asp:DropDownList>
            </td></tr>
        <tr><td><asp:Label ID="Label2" runat="server" Text="Display City" Font-Size="Large"></asp:Label>
            </td><td>
        <asp:Label ID="lblDisplayCity" runat="server" Font-Size="XX-Large" ForeColor="Red"></asp:Label>
            </td></tr>
    </table>

    </div>
    </form>
</body>
</html>


                                   C# CODING


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblDisplayCity.Text = DropDownList1.SelectedItem.Value.ToString();
    }

}



First - Add New - Web Form - Select DropDownList,Label From ToolBox  - Dropdownlist -Propert - Autopostback=True





Next - DropDownList - Right Click - Edit Item - Add - ListItem






Next - Add Text & Value - OK





Next - Double Click - DropDownList - Display DropDownList Value