You are on page 1of 21

Dev Shah

Div - B
Roll no -100
TYBCA

WAD Practical 2
August 02, 2022

Program 1 :
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)
{

}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "1")
{
Label1.Text = "15.00";
}
else if (DropDownList1.SelectedValue=="2")
2 Dev shah Roll no- 100 Div - B

{
Label1.Text="80.00";
}
else if(DropDownList1.SelectedValue=="3")
{
Label1.Text="45.00";
}
else if (DropDownList1.SelectedValue == "4")
{
Label1.Text = "30.00";
}
else
{
Label1.Text = "0.00";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int A;
A = Convert.ToInt32(TextBox1.Text);
double b;
b = Convert.ToDouble(Label1.Text);
double total = A*b;
Label2.Text = total.ToString();
}
}
3 Dev shah Roll no- 100 Div - B

Output 1:

Program 2 :
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)


{

}
4 Dev shah Roll no- 100 Div - B

protected void Button1_Click(object sender, EventArgs e)


{
if (RadioButtonList1.SelectedValue == "2")
{
form1.Attributes.Add("style", "background-color : red;");
}
else if (RadioButtonList1.SelectedValue == "3")
{
form1.Attributes.Add("style", "background-color : green;");
}
else if (RadioButtonList1.SelectedValue == "4")
{
form1.Attributes.Add("style", "background-color : yellow;");
}
}
}

Output 2:

Program 3 :
using System;
5 Dev shah Roll no- 100 Div - B

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)
{
Panel2.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
Response.Write("Congrulation Order placed succesfully");
Response.Write("<br/>");
Response.Write("<br/>");
Response.Write("Your ordered items is/are");
Response.Write("<br/>");
Response.Write("<br/>");

foreach (ListItem li in CheckBoxList2.Items)


{
if (li.Selected==true)
{
6 Dev shah Roll no- 100 Div - B

Response.Write(li.Text);
Response.Write("<br/>");
}
}

}
protected void CheckBoxList2_SelectedIndexChanged(object sender, EventArgs e)
{

}
}

Output 3:
7 Dev shah Roll no- 100 Div - B

Program 4 :
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)
{
HttpCookie coke = Request.Cookies["PageCount"];
if (coke == null)
{
coke = new HttpCookie("PageCount");
coke.Value = "1";
coke.Expires = DateTime.Now.AddDays(365);
}
else if(int.Parse(coke.Value)>0)
{
int page_counts = int.Parse(coke.Value);
coke.Value = (page_counts + 1).ToString();
coke.Expires = DateTime.Now.AddDays(365);
}
Response.Cookies.Add(coke);
Label1.Text = coke.Value;
8 Dev shah Roll no- 100 Div - B

}
}

Output 4:

Program 5:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page


{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);

protected void Page_Load(object sender, EventArgs e)


{
9 Dev shah Roll no- 100 Div - B

//Checking Connection State and opening if closed


if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (!Page.IsPostBack)
{
//Call countries DropDownList on page load event
BindContriesDropDownList();
}
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int CountryId = Convert.ToInt32(ddlCountry.SelectedValue);
//Select all States corresponding to the selected Country
SqlDataAdapter adp = new SqlDataAdapter("select * from Tbl_State where
Country_ID_Fk=" + CountryId, con);
DataSet ds = new DataSet();
adp.Fill(ds);
ddlState.DataSource = ds;
ddlState.DataTextField = "State_Name";
ddlState.DataValueField = "State_Id_Pk";
ddlState.DataBind();
ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
//If State is not selected then clear City DropDownList also
if (ddlState.SelectedValue == "0")
10 Dev shah Roll no- 100 Div - B

{
ddlCity.Items.Clear();
ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));
}
}
catch (Exception ex)
{
//Printing any exception if occcured.
Response.Write("Error occured: " + ex.Message.ToString());
}
finally
{
//Close the connection
con.Close();
}
}
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int StateId = Convert.ToInt32(ddlState.SelectedValue);
//Select all Cities corresponding to the selected State
SqlDataAdapter adp = new SqlDataAdapter("select * from Tbl_City where
State_ID_Fk=" + StateId, con);
DataSet ds = new DataSet();
adp.Fill(ds);
ddlCity.DataSource = ds;
ddlCity.DataTextField = "City_Name";
11 Dev shah Roll no- 100 Div - B

ddlCity.DataValueField = "City_id_pk";
ddlCity.DataBind();
ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));
}
catch (Exception ex)
{
Response.Write("Error occured : " + ex.Message.ToString());
}
finally
{
con.Close();
}
}

protected void BindContriesDropDownList()


{
try
{
SqlDataAdapter adp = new SqlDataAdapter("select * from Tbl_Country", con);
DataSet ds = new DataSet();
adp.Fill(ds);
ddlCountry.DataSource = ds;
ddlCountry.DataTextField = "Country_Name";
ddlCountry.DataValueField = "Country_Id_Pk";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));
12 Dev shah Roll no- 100 Div - B

}
catch (Exception ex)
{
Response.Write("Error occured : " + ex.Message.ToString());
}
finally
{
con.Close();
}
}

Output 5:

Program 6:
using System;
using System.Collections.Generic;
using System.Linq;
13 Dev shah Roll no- 100 Div - B

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
String str;
str = Server.MapPath("images");
string fileextension = Path.GetExtension(FileUpload1.FileName);
if (FileUpload1.HasFile == true)
{
if (fileextension.ToLower() != ".jpeg" &&
fileextension.ToLower() != ".jpg")
{
Label1.Text = "Only .jpg and .jpeg file allowed...";
}

else
{
int size = FileUpload1.PostedFile.ContentLength;
if (size > 10000000000)
14 Dev shah Roll no- 100 Div - B

{
Label1.Text = "File size exceeds 1 KB";
}
else
{
str = str + "\\" + FileUpload1.FileName;
FileUpload1.SaveAs(str);
Label1.Text = "File has been succesfully uploaded" + "uploaded at" + str;
Image1.ImageUrl = "Images\\" + FileUpload1.FileName;
}
}
}
else
{
Label1.Text = "No file selected... Please select File...";
}
}
}

Output 6:
15 Dev shah Roll no- 100 Div - B

Program 7:
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)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie coke = new HttpCookie("userinfo");

coke["NO"] = TextBox1.Text;
coke["Name"] = TextBox2.Text;
coke["price"] = TextBox3.Text;
coke["quantity"] = TextBox4.Text;
Response.Cookies.Add(coke);
Response.Redirect("default2.aspx");
}
}
16 Dev shah Roll no- 100 Div - B

Output 7:

Program 8:
<%@ 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>
17 Dev shah Roll no- 100 Div - B

</head>
<body>
<form id="form1" runat="server">
<div>

<asp:ImageMap ID="ImageMap1" runat="server" Height="47px"


ImageUrl="~/photo.jpg" onclick="ImageMap1_Click" Width="325px">
<asp:RectangleHotSpot Bottom="27" Left="30" Right="71" Top="16"
HotSpotMode="Navigate" NavigateUrl="~/Default2.aspx" />
<asp:RectangleHotSpot Bottom="27" HotSpotMode="Navigate" Left="107"
NavigateUrl="~/Default3.aspx" Right="159" Top="16" />
<asp:RectangleHotSpot Bottom="27" HotSpotMode="Navigate" Left="205"
NavigateUrl="~/Default4.aspx" Right="251" Top="16" />
</asp:ImageMap>
<br />
<br />
<br />
<br />

</div>
</form>
</body>
</html>
18 Dev shah Roll no- 100 Div - B

Output 8 :

Program 9:
<%@ 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>
19 Dev shah Roll no- 100 Div - B

<asp:AdRotator ID="AdRotator1" runat="server"


AdvertisementFile="~/XMLFile2.xml"/>

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

Xml code:
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>1.jpg</ImageUrl>
<AlternateText>
</AlternateText>
<NavigateUrl>http://www.google.com</NavigateUrl>
</Ad>
<Ad>
<ImageUrl>2.jpg</ImageUrl>
<AlternateText></AlternateText>
<NavigateUrl></NavigateUrl>
</Ad>
<Ad>
<ImageUrl>3.jpg</ImageUrl>
<AlternateText></AlternateText>
<NavigateUrl></NavigateUrl>
</Ad>
20 Dev shah Roll no- 100 Div - B

</Advertisements>

Output 9:

Program 10:
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)
{
21 Dev shah Roll no- 100 Div - B

}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = Calendar1.SelectedDate.ToString();
}
}

Output 10:

You might also like