Tuesday, April 3, 2012

First ASP

here is the asp code for Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="Default.aspx.cs" 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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" 
            BorderColor="White" BorderWidth="1px" 
            Font-Names="Verdana" Font-Size="9pt" 
            ForeColor="Black" Height="190px" 
NextPrevFormat="FullMonth" Width="350px" >
            <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
            <NextPrevStyle Font-Bold="True" Font-Size="8pt" 
ForeColor="#333333" 
                VerticalAlign="Bottom" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <SelectedDayStyle BackColor="#333399" 
ForeColor="White" />
            <TitleStyle BackColor="White" BorderColor="Black" 
BorderWidth="4px" 
                Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
            <TodayDayStyle BackColor="#CCCCCC" />
        </asp:Calendar>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList><br />
        <asp:Label ID="Label1" runat="server" Text="Enter Your Name" ></asp:Label>
        <asp:TextBox ID="txtName"
            runat="server" ></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="Submit" 
            onclick="Button1_Click" />
<br />
        <asp:Label ID="lblResult" runat="server" Text="Label">
</asp:Label>
    </div>
    </form>
</body>
</html>


Here is the c# code Behind: Default.aspx.cs


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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //an array of animals

        if (!IsPostBack)
        {
            string[] animals = new string[4];
            animals[0] = "Grizzly Bear";
            animals[1] = "hamster";
            animals[2] = "Zebra";
            animals[3] = "Giraffe";

            //binding the data to the control
            DropDownList1.DataSource = animals;
            DropDownList1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //retrieved all three values
        string animal = DropDownList1.SelectedItem.ToString();
        string date = Calendar1.SelectedDate.ToShortDateString();
        string name = txtName.Text;
        lblResult.Text = name + ", your animal is " 
                        + animal 
                        + ", your selected date is " 
                        + date;


    }
}

No comments:

Post a Comment