DropDownList Example in ASP.NET using C#
DropDownList.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master"
AutoEventWireup="true" CodeFile="DropDownList.aspx.cs" Inherits="DropDownList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style3
{
color: #800000;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<h2 style="color:Green">DropDownList in ASP.NET 4 , C#</h2>
<strong><span class="style3">Enter first number:</span>
</strong>
<br />
<asp:TextBox ID="txt1" runat="server" Text="12"/>
<br />
<br />
<span class="style3">
<strong>Enter second number:
</strong>
</span>
<br />
<asp:TextBox ID="txt2" runat="server" Text="3" />
<br />
<br />
<span class="style3">
<strong>Select operation:
</strong>
</span>
<br />
<asp:DropDownList ID="drp1" runat="server" Width="145px"
Font-Bold="True" ForeColor="#006666"
onselectedindexchanged="drp1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem>----Select----</asp:ListItem>
<asp:ListItem>Addition</asp:ListItem>
<asp:ListItem>Subtraction</asp:ListItem>
<asp:ListItem>Multiplication</asp:ListItem>
<asp:ListItem>Division</asp:ListItem>
</asp:DropDownList>
</div>
<br />
<asp:Label ID="label1" runat="server" Font-Bold="True" ForeColor="#000099" />
</asp:Content>
DropDownList.aspx.cs (C# code file):
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 drp1_SelectedIndexChanged(object sender, EventArgs e)
{
double firstno = Convert.ToDouble(txt1.Text);
double secondno = Convert.ToDouble(txt2.Text);
if(drp1.SelectedIndex == 1)
{
double add = firstno + secondno;
label1.Text = "Addition is :" + add;
}
if (drp1.SelectedIndex == 2)
{
double sub = firstno - secondno;
label1.Text = "Subtraction is :" + sub;
}
if (drp1.SelectedIndex == 3)
{
double mul = firstno * secondno;
label1.Text = "Multiplication is :" + mul;
}
if (drp1.SelectedIndex == 4)
{
double div = firstno / secondno;
label1.Text = "Division is :" + div;
}
}
}
OUTPUT
No comments:
Post a Comment