Wednesday 23 July 2014

asp.net 13: dropdown list(auto postback)

program to select roll number and display name vice versa using auto post back property.


-----------------------------------------DESIGN-----------------------------------------------------



<%@ 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>
   
        &nbsp;
        <asp:Label ID="Label1" runat="server" ForeColor="Red"
            Text="DEMO OF AUTOPOSTBACK  PROPERTY"></asp:Label>  
        <br />
        <br />
   
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem>Select Enrollment No</asp:ListItem>
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            <asp:ListItem></asp:ListItem>
        </asp:DropDownList>
        <br />
        <br />
   
    </div>
    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
        Height="38px" Width="148px">
        <asp:ListItem>Select Name</asp:ListItem>
        <asp:ListItem>Meru</asp:ListItem>
        <asp:ListItem>Johar</asp:ListItem>
        <asp:ListItem>sanjay</asp:ListItem>
        <asp:ListItem>Akshay</asp:ListItem>
        <asp:ListItem>Nikunj</asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   
<asp:Button ID="Button1" runat="server" Text="OK" />
    <br />
    <br />
    <asp:ListBox ID="ListBox1" runat="server" Height="126px" Width="145px">
    </asp:ListBox>
    </form>
</body>
</html>

-----------------------------------------code---------------------------------------------------------




Partial Class _Default
    Inherits System.Web.UI.Page
    Dim a As Integer
    Dim b As Integer
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,      ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        a = DropDownList1.SelectedIndex
        DropDownList2.SelectedIndex = a
        ListBox1.Items.Clear()
End Sub

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        b = DropDownList2.SelectedIndex
        DropDownList1.SelectedIndex = b
        ListBox1.Items.Clear()
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
 ListBox1.Items.Add("Enrollment No:" & DropDownList1.SelectedItem.ToString())
 ListBox1.Items.Add("Name:" & DropDownList2.SelectedItem.ToString())
End Sub
End Class
-----------------------------------------output----------------------------------------------------

   
umesh sohaliya
codestrew

No comments:

Post a Comment