Sunteți pe pagina 1din 88

TYBSC.IT ASP.

NET WITH C#

Practical No.-03(1)
Aim:-Create an application that allows the user to enter a number in the textbox named
getnum. Check whether the number in the textbox getnum is palindrome or not. Print the
message accordingly in the label control named lbldisplay when the user clicks on the Button
check.
Design:-

Property Table:-

CONTROL PROPERTY VALUE


Label1 Text Enter no:
TextBox1 ID Text
Label2 Text Result
Label2 ID lbldisplay
Button Text Check
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class palindrone : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int num = int.Parse(getnum.Text);
int n, rev = 0, d;
n = num;
while (n > 0)
{
d = n % 10;
n = n / 10;
rev = rev * 10 + d;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 1
TYBSC.IT ASP.NET WITH C#
}
if (rev == num)
lblDisplay.Text = lblDisplay.Text + num + "is a palindrone number";
else
lblDisplay.Text = lblDisplay.Text + num + "is not a palindrone
number";
}
}
Browser Output:-

Practical No.-03(2)
Aim:-Create an application which will ask the user to input his name and a message, display
the two items concatenated in a label, and change the format of the label using radio buttons
and check boxes for selection, the user can make the label text bold, underlined or italic and
change its color. Include buttons to display the message in the label, clear the text boxes and
label, and exit.
Design:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 2
TYBSC.IT ASP.NET WITH C#

Property Table:-
CONTROL PROPERTY VALUE
Lable1 Text Enter your name:
TextBox1 ID txt1
CheckBox1 Text chkbold
CheckBox1 AutoPostBack True
CheckBox2 Text chkitalic
CheckBox2 AutoPostBack True
CheckBox3 Text chkunderline
CheckBox3 AutoPostBack True
RadioButton1 Text rbtn1
RadioButton1 GroupName Color
RadioButton1 AutoPostBack True
RadioButton2 Text rbtn2
RadioButton2 GroupName Color
RadioButton2 AutoPostBack True
RadioButton3 Text rbtn3
RadioButton3 GroupName Color
RadioButton3 AutoPostBack True
Label2 Text Enter a message:
Button1 ID Display
Button2 ID Clear
TextBox2 ID Text
Label3 Text lblmessage
Code:-
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 CheckBox3_CheckedChanged(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 3
TYBSC.IT ASP.NET WITH C#
{
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
}
protected void btn1_Click(object sender, EventArgs e)
{
if (chkbold.Checked == true)
lblmessage.Font.Bold = true;
else
lblmessage.Font.Bold = false;
if (chkitalic.Checked == true)
lblmessage.Font.Italic = true;
else
lblmessage.Font.Italic = false;
if (chkunderline.Checked == true)
lblmessage.Font.Underline = true;
else
lblmessage.Font.Underline = false;
if (rbtn1.Checked == true)
lblmessage.ForeColor = System.Drawing.Color.Red;
else if (rbtn2.Checked == true)
lblmessage.ForeColor = System.Drawing.Color.Blue;
else if (rbtn3.Checked == true)
lblmessage.ForeColor = System.Drawing.Color.Purple;
lblmessage.Text = "name:" + txt1.Text + "<br/>" + "message:" +
txt1.Text;
}
protected void btn2_Click(object sender, EventArgs e)
{
txt1.Text = "";
txt1.Text = "";
lblmessage.Text = "";
}
}
Browser Output:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 4
TYBSC.IT ASP.NET WITH C#

Practical No.-03(3)
Aim:-List of employees is available in listbox. Write an application to add selected or all
records from listbox to textbox (assume multi-line property of textbox is true).
Design:-

Property Table:-
CONTROL PROPERTY VALUE
Button1 ID Add
ListBox1 AutoPostBack True
ListBox1 Items Jancy
ListBox1 Items Prajkata
ListBox1 Items Dona
ListBox1 Items Anchiti
ListBox1 Items Rutu
Code:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 5
TYBSC.IT ASP.NET WITH C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnaddclick_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected == true)
txt1.Text += ListBox1.Items[i].Text + "\n";
}
}
}
Browser Output:-

Practical No.-03(4)
Aim:- Create an application that calculates the total of fat, carbohydrate and protein calories.
Allow user to enter (in textboxes) the grams of fats, carbohydrate and protein. Each gram of
fat is nine calories, whereas a gram of protein or carbohydrate is four calories. Display the
total calories for the current food item in a label. Use two other labels to display an
accumulated sum of calories and a count of the items entered. The form should have three
text boxes for the user to enter the grams for each category. Include labels next to each text
box indicating what the user is to enter. Include Buttons to calculate and to clear text boxes.
Write the code for each Button.

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 6
TYBSC.IT ASP.NET WITH C#
Design:-

Property Table:-
CONTROL PROPERTY VALUE
Label1 Text Fat
Label2 Text Carbohydrates
Label3 Text Proteins
TextBox1 ID TextBox1
TextBox2 ID TextBox2
TextBox3 ID TextBox3
Button1 Text Calculate
Button1 ID lbldisplay
Label4 Text Label

Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnclick_Click(object sender, EventArgs e)
{
int curr_cal = (Convert.ToInt32(TextBox1.Text) * 9 +
Convert.ToInt32(TextBox2.Text) * 4 + Convert.ToInt32(TextBox3.Text)
* 4);
lbldisplay.Text = Convert.ToString(curr_cal);

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 7
TYBSC.IT ASP.NET WITH C#
}
}
Browser Output:-

Practical No:04
Practical No:4(1)(Program using ASP.NET Validation Controls)
Aim:- Create the application that accepts name, password ,age , email id, and user id. All
the information entry is compulsory. Password should be reconfirmed. Age should be within
21 to 30. Email id should be valid. User id should have at least a capital letter and digit as
well as length should be between 7 and 20 characters.
Design:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 8
TYBSC.IT ASP.NET WITH C#

Property Table:-
CONTROL PROPERTY VALUE
Label1 Text Name:
ID Lblname
Label2 Text Password
ID lblpassword
Label3 Text Age
ID lblage
Label4 Text Emailid
ID lblemail
Label5 Text Userid:
ID lbluser
Label6 Text Confirm password
ID lbl6
TextBox1 ID txt1
TextBox2 ID txt2
TextBox3 ID txt3
TextBox4 ID txt4
TextBox5 ID txt5
TextBox6 ID txt6
TextBox6 TextMode Password
RequiredFieldValidation Display Static
ID RequiredFieldValidation
ControlToValidate txt1
ErrorMessage *pls enter name
ForeColor Red
Text *pls enter name
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 9
TYBSC.IT ASP.NET WITH C#
RequiredFieldValidation Display Static
ID RequiredFieldValidation
ControlToValidate txt2
ErrorMessage *pls enter password
ForeColor Red
Text *pls enter password
SetFocusOnError True
CompareValidator ForeColor Red
ErrorMessage *pls enter password
ControlToCompare txt2
ControlToValidate txt6
RangeValidator ID RangeValidator2
ErrorMessage *pls enter valid age
ForeColor Red
Display Static
SetFocusOnError True
ControlToValidate txt3
MinimumValue 16
MaximumValue 60
Type Integer
RegularExpressionValidator ID RegularExpressionValidator
ErrorMessage *pls enter valid email Id
ControlToValidate txt4
ForeColor Red
ValidationExpression Internet email-address
CustomValidator ControlToValidate txt5
ID CustomValidator1
ForeColor Red
SetFocusOnError True
Display Static
ErrorMessage *pls enter user Id
Text *pls enter user Id
Button1 ID btn1
Text Submit
Button2 ID btn2
Text Clear

Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 10
TYBSC.IT ASP.NET WITH C#
using System.Web.UI.WebControls;

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


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

}
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
String str = args.Value;
args.IsValid = false;
if (str.Length < 7 || str.Length > 20)
{
return;
}
bool capital = false;
foreach (char ch in str)
{
if (ch >= 'A' && ch <= 'Z')
{
capital = true;
break;
}
}
if (!capital) return;
bool digit = false;
foreach (char ch in str)
{
if (ch >= '0' && ch <= '9')
{
digit = true;
break;
}

}
if (!digit) return;
args.IsValid = true;

}
protected void btn1_Click(object sender, EventArgs e)
{
Response.Write("login successful....");
}

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 11
TYBSC.IT ASP.NET WITH C#
protected void btn2_Click(object sender, EventArgs e)
{

}
}

Browser Output:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 12
TYBSC.IT ASP.NET WITH C#
Practical No:4(2)
Practical No:2(2)(Program using ASP.NET Navigation Controls)
Aim: Create a website for bank and include all types of navigation.
Design:-

Code:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~\" title="Bank of India" description="Online banking">
<siteMapNode url="Home.aspx" title="Home" description="Go to homepage" />
<siteMapNode url="About us.aspx" title="About us" description="About us" />

<siteMapNode url="Statistics.aspx" title="Statistics" description="Statistics">


<siteMapNode url="Data Release.aspx" title="Data Realease" description="Data
Realease" />
<siteMapNode url="Database on India Economy.aspx" title="Database on India Economy"
description="Database" />
<siteMapNode url="Service.aspx" title="Service" description="Service" />
</siteMapNode>

<siteMapNode url="Publications.aspx" title="Publication" description="Publications">

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 13
TYBSC.IT ASP.NET WITH C#
<siteMapNode url="Annual.aspx" title="annual" description="Annual details" />
<siteMapNode url="Monthly.aspx" title="monthly" description="Monthly details" />
<siteMapNode url="Reports.aspx" title="reports" description="Reports details" />
</siteMapNode>
</siteMapNode>
</siteMap>
Browser Output:-

Browser Output:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 14
TYBSC.IT ASP.NET WITH C#

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 15
TYBSC.IT ASP.NET WITH C#

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 16
TYBSC.IT ASP.NET WITH C#

Practical No:05(a)
AIM:-Create a web App to display all the Empname and DeptId of the employee from the Database using
SQL Source control and bind it to GridView.Database Fields are(DeptId,DeptName,EmpName,Salary).

Steps:
1. Filenewwebsiteempty websitename itok
2. Right click on website madeadd new itemsql server databasename itaddyes
3. Right click on table In server exploreradd new tableadd columnssave the table
4. Right click on table made show table dataadd values
5. Right click on websiteadd new itemwebformname it
6. Go to design view
7. Add a gridviewbelow that add sqldatasource
8. Configure sqldatasourcethen add it to the gridview
9. Go to gridview menu enable sorting
Design:-

DatabaseTable:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 17
TYBSC.IT ASP.NET WITH C#

BROWSER OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 18
TYBSC.IT ASP.NET WITH C#

Practical No:05(b)
AIM:-Create a Login Module which adds Username and Password in the database. Username in the
database should be a primary key.

Steps2:
1. Filenewwebsiteempty websitename itok
2. Right click on website madeadd new itemsql server databasename itaddyes
3. Right click on table In server exploreradd new tableadd columnssave the table
4. Right click on table made show table dataadd values
5. Right click on websiteadd new itemwebformname it
6. Go to design viewadd form for login
7. Add sqldatasourceconfigure it
8. Write code

Design:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 19
TYBSC.IT ASP.NET WITH C#
Database Table:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default123456 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.InsertParameters["User"].DefaultValue = TextBox1.Text;
SqlDataSource1.InsertParameters["Password"].DefaultValue = TextBox2.Text;
SqlDataSource1.Insert();
}
}

Database table data added:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 20
TYBSC.IT ASP.NET WITH C#
Broswer Output:

Practical No:05(c)
AIM:Create a Login Module which adds Username and Password in the database. Username in the
database should be a primary key.

Steps2:
1. Filenewwebsiteempty websitename itok
2. Right click on website madeadd new itemsql server databasename itaddyes
3. Right click on table In server exploreradd new tableadd columnssave the table
4. Right click on table made show table dataadd values
5. Right click on websiteadd new itemwebformname it
6. Go to design viewadd form for login
7. Add sqldatasourceconfigure it
8. Write code

DESIGN:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 21
TYBSC.IT ASP.NET WITH C#

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 22
TYBSC.IT ASP.NET WITH C#

CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default99.aspx.cs"
Inherits="Default99" %>

<!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:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [detailsofemp] WHERE [DeptId] = @DeptId"
InsertCommand="INSERT INTO [detailsofemp] ([DeptId], [DeptName],
[EmpName], [Salary]) VALUES (@DeptId, @DeptName, @EmpName, @Salary)"
SelectCommand="SELECT * FROM [detailsofemp]"
UpdateCommand="UPDATE [detailsofemp] SET [DeptName] = @DeptName,
[EmpName] = @EmpName, [Salary] = @Salary WHERE [DeptId] = @DeptId">
<DeleteParameters>
<asp:Parameter Name="DeptId" Type="Byte" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="DeptId" Type="Byte" />
<asp:Parameter Name="DeptName" Type="String" />
<asp:Parameter Name="EmpName" Type="String" />
<asp:Parameter Name="Salary" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="DeptName" Type="String" />
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 23
TYBSC.IT ASP.NET WITH C#
<asp:Parameter Name="EmpName" Type="String" />
<asp:Parameter Name="Salary" Type="Decimal" />
<asp:Parameter Name="DeptId" Type="Byte" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="DeptId" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="DeptId" HeaderText="DeptId"
ReadOnly="True"
SortExpression="DeptId" />
<asp:BoundField DataField="DeptName" HeaderText="DeptName"
SortExpression="DeptName" />
<asp:BoundField DataField="EmpName" HeaderText="EmpName"
SortExpression="EmpName" />
<asp:BoundField DataField="Salary" HeaderText="Salary"
SortExpression="Salary" /></Columns>
</asp:GridView>
<br /> </div> </form>
</body>
</html>
BROWSER OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 24
TYBSC.IT ASP.NET WITH C#

Practical No:06(a)
AIM: Create a web page to display the news from the table Notice(id,
news_details). Use AJAX CONTROLS.

DESIGN:

CODE:
<%@ 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:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>
<asp:Label ID="lbl1" runat="server" Text="BreakingNews"></asp:Label>
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 25
TYBSC.IT ASP.NET WITH C#
<br />
<br />
<asp:Button ID="btn" runat="server" onclick="btn_Click" Text="BreakingNews" />
</div>
</form>
</body>
</html>

SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\TEMP.VSIT-X103-
72.001\Documents\Visual Studio
2010\WebSites\WebSite1\App_Data\Database.mdf;Integrated Security=True;User
Instance=True");
con.Open();
SqlCommand com = new SqlCommand("Select * from NewsVsit", con);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
lbl1.Text += "<br>" + dr[1].ToString() ;
}
con.Close();
}
}

BROWSER OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 26
TYBSC.IT ASP.NET WITH C#

Practical No:06(b)
AIM: In the above website also display the feedback on the browser as work
is in progress.

DESIGN:

CODE:
<%@ 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">
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 27
TYBSC.IT ASP.NET WITH C#
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image2" runat="server" Height="150px" ImageUrl="~/ajsdh.png"
Width="200px" />
<br />
<asp:Label ID="Label1" runat="ser
ver" Text="Page Showing Breaking News"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lbl1" runat="server" Text="BreakingNews"></asp:Label>
<br />
<br />
<asp:Button ID="btn" runat="server" onclick="btn_Click" Text="BreakingNews" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<asp:Label ID="Label2" runat="server" Text="Work in Progress"></asp:Label>
</ProgressTemplate>
</asp:UpdateProgress>
<br />
</div>
</form>
</body>
</html>
SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
}
protected void btn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\TEMP.VSIT-X103-
72.001\Documents\Visual Studio
2010\WebSites\WebSite1\App_Data\Database.mdf;Integrated Security=True;User
Instance=True");
con.Open();

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 28
TYBSC.IT ASP.NET WITH C#
SqlCommand com = new SqlCommand("Select * from NewsVsit", con);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
lbl1.Text += "<br>" + dr[1].ToString() ;
}
con.Close(); } }
BROWSER OUTPUT:

Practical No:06(c)
AIM: Create a web page to display the cricket score from the table cricket (id,
name, score).
Refresh the website automatically after every 30 seconds.

DESGIN:

CODE:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 29
TYBSC.IT ASP.NET WITH C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Score.aspx.cs"
Inherits="Score" %>
<!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:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="CricketScoreBoard"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="350" ontick="Timer1_Tick">
</asp:Timer>
<br />
</div></form>
</body>
</html>

SOURCECODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Score : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Timer1_Tick(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\TEMP.VSIT-X103-
72.001\Documents\Visual Studio
2010\WebSites\WebSite1\App_Data\Database2.mdf;Integrated Security=True;User
Instance=True");
SqlDataReader dr = null;
con.Open();
SqlCommand com = new SqlCommand("Select * from ScoreCard", con);
dr = com.ExecuteReader();
while (dr.Read())
{
Label1.Text +="<br>" +dr[0].ToString() +" "+dr[1].ToString() +" "
+dr[2].ToString();
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 30
TYBSC.IT ASP.NET WITH C#
}
con.Close();
}
}

BROWSER OUTPUT:

Practical No:07(a)
AIM:Program using Language Integrated Query.
DESIGN:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 31
TYBSC.IT ASP.NET WITH C#

CODE:
student.xml
<?xml version="1.0" encoding="utf-8" ?>
<students>
<student>
<srollno>
1
</srollno>
<sname>
Mitali
</sname>
<saddress>
Dadar
</saddress>
<sfees>
10000
</sfees>
</student>
<student>
<srollno>
2
</srollno>
<sname>
Jancy
</sname>
<saddress>
Sion
</saddress>
<sfees>
10000
</sfees>
</student>
<student>
<srollno>
3
</srollno>
<sname>
Dona
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 32
TYBSC.IT ASP.NET WITH C#
</sname>
<saddress>
Vasai
</saddress>
<sfees>
10000
</sfees>
</student>
</students>

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Xml.Linq;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath("XMLFile.xml"));
var studs = from s in xmlDoc.Descendants("student")
select s;
GridView1.DataSource = studs;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}

SOURCE CODE:
<%@ 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:GridView ID="GridView1" runat="server"


onselectedindexchanged="GridView1_SelectedIndexChanged">
</asp:GridView>

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 33
TYBSC.IT ASP.NET WITH C#
</div>
</form>
</body>
</html>

OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 34
TYBSC.IT ASP.NET WITH C#

Practical No:07(b)
AIM:Programs using Language Intergrated Query.
DESIGN:

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class Class1


{
public string PID { get; set; }
public string PName { get; set; }
public int PPrice { get; set; }
public int PWeight { get; set; }

}
SOURCE CODE:
Keep till runat=server>

Code-
using System;
using System.Collections.Generic;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 35
TYBSC.IT ASP.NET WITH C#
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
public List<Class1> GetProdData()
{
return new List<Class1>
{
new Class1{PID="P101", PName="Laptop", PPrice=40000, PWeight=1500},
new Class1{PID="P102", PName="Dslr", PPrice=45000, PWeight=1000},
new Class1{PID="P103", PName="Desktop", PPrice=20000, PWeight=3500}
};
}

protected void Page_Load(object sender, EventArgs e)


{
var prod = GetProdData();
var query = from f in prod orderby f.PName select f;
this.GridView1.DataSource = query;
this.GridView1.DataBind();

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

}
}

OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 36
TYBSC.IT ASP.NET WITH C#

Practical No:07(c)
AIM:Programs using Language Intergrated Query.
New website make tableadd linq to sql classes.. drag table webform.. gridvie code
on pageload
DESIGN:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 37
TYBSC.IT ASP.NET WITH C#

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.Linq;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataClassesDataContext dc = new DataClassesDataContext();
var query = from m in dc.employeetables select m;
GridView1.DataSource = query;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}

OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 38
TYBSC.IT ASP.NET WITH C#

Practical No:-08(A)

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 39
TYBSC.IT ASP.NET WITH C#
AIM:Create a web page to give different color effects for paragraph tags,headings tags and
complete web page using JQuery.
DESIGN:

SOURCE CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>
<!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">
<script type="text/javascript">
$(document).ready(function () {
$("*").css("background-color","Red");
$("h1").css("color","Blue");
$("h2").css("color","Black");
$("p").css("color","purple");
$("p#intro").css("color","green");
});

</script>
<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">


<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-1.4.1.js"/>
</Scripts>

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 40
TYBSC.IT ASP.NET WITH C#
</asp:ScriptManager>

<h1>
This is Jquery Example.</h1>
<h2>
This is Jquery heading.</h2>
<p>
First Paragraph is about introducation.</p>
<p>
Second Paragraph having details about it.</p>
<p id="intro">
Third Paragraph is with id introducation.<br/>
</p>

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

OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 41
TYBSC.IT ASP.NET WITH C#

Practical No:-08(B)
AIM:Create a web page to display hide,show,toggle,slideUp,slideDown effects for
paragraph tags,using JQuery.
DESIGN:

SOURCE CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs"
Inherits="Default3" %>

<!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>
<script type="text/javascript">
$(document).ready(function () {
$("p").hide(1000);
$("p").show(2000);
$("p").toggle(3000);
$("p").slideDown(4000);
$("p").slideUp(5000);
$("h1").animate({opacity:04,
marginLeft: '100px',
fontSize:'50px'},8000);
});
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-1.4.1.js" />
</Scripts>
</asp:ScriptManager>
<p>
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 42
TYBSC.IT ASP.NET WITH C#
<br />
First Paragraph.</p>
<h1>
First Heading.</h1>

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

OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 43
TYBSC.IT ASP.NET WITH C#

Practical No:-08(C)
AIM:Create a web page to apply fadein,fadeout,slide toggle,toggle effects for paragraph
tags using JQuery.
DESIGN:

SOURCE CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs"
Inherits="Default3" %>

<!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>
<script type="text/javascript">
$(document).ready(function () {
$("p").fadeIn(1000);
$("p").fadeOut(2000);
$("p").fadeTo(3000,0.6);
$("p").slidetoggle(4000);
$("h1").animate({opacity:04,
marginLeft: '100px',
fontSize:'50px'},8000);
});
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 44
TYBSC.IT ASP.NET WITH C#
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-1.4.1.js" />
</Scripts>
</asp:ScriptManager>
<p>
<br />
First Paragraph.</p>
<h1>
First Heading.</h1>

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

OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 45
TYBSC.IT ASP.NET WITH C#

Practical No: 09(1)


AIM:Set the label border color of rollno to red using css.
DESIGN:

CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs"
Inherits="Default4" %>
<!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:Label ID="Label1" runat="server" Text="Enter RollNo:" BorderColor="Red"


BorderStyle="Dashed"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Enter Name:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Enter Marks:"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 46
TYBSC.IT ASP.NET WITH C#
<br /> <br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" Text="Clear" />
</div> </form></body></html>
BROWSER OUTPUT:

Practical No: 09(2)


AIM: Set the font-Arial , font style-bond , font size-18px of different controls(ie. Label,
textbox, button) using css.

DESIGN:

CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs"
Inherits="Default5" %>
<!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>
<style type="text/css">

.newStyle2
{
font-family: "Arial Black";
font-size: medium;
font-weight: lighter;
font-style: normal;
font-variant: normal;
color: #FF0000;
text-decoration: underline;
} </style>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" CssClass="newStyle2"
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 47
TYBSC.IT ASP.NET WITH C#
Text="Welcome Messsage:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" CssClass="newStyle2"></asp:TextBox>
</form>
</body>
</html>
BROWSER OUTPUT:

Practical No: 09(3)


AIM: Design the same webpages for BMS, BAF, BscIT students and apply same background
color for all the pages using css.
DESIGN:

CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs"
Inherits="Default6" %>
<!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:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/bsc it.aspx">bsc


it</asp:HyperLink>
</div>
<br />

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 48
TYBSC.IT ASP.NET WITH C#
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="~/baf.aspx">Baf</asp:HyperLink>
<br />
<br />
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="~/bms.aspx">Bms</asp:HyperLink>
</form>
</body>
</html>

Bsc
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="bsc it.aspx.cs"
Inherits="bsc_it" %>

<!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>
<link href="mystyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
bsc it</div></form></body></html>
Bms
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="bms.aspx.cs" Inherits="bms" %>

<!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>
<link href="mystyle.css" rel="stylesheet" type="text/css" />
</head> <body>
<form id="form1" runat="server">
<div>
bms </div> </form></body></html>
Baf
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="baf.aspx.cs" Inherits="baf" %>

<!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>
<link href="mystyle.css" rel="stylesheet" type="text/css" /></head><body>
<form id="form1" runat="server">
<div> baf </div> </form> </body> </html>
BROWSER OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 49
TYBSC.IT ASP.NET WITH C#

Practical No: 09(4)


AIM: Change the font family and color of all heading of above webpage using css.
DESIGN:

CODE:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs"


Inherits="Default7" %>

<!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>
<style type="text/css">
h1,h2,h3
{
font-family: "Arial Black";
font-size: large;
font-weight: bold;
font-style: normal;
font-variant: small-caps;
color: #FF0000;
text-decoration: underline;
} </style> </head>
<body style="font-family: AngsanaUPC">
<form id="form1" runat="server">
<h1>
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 50
TYBSC.IT ASP.NET WITH C#
bsc it</h1> <h2> bms</h2> <h3>
baf</h3> </form>
</body>
</html>

BROWSER OUTPUT:

Practical No: 04(5)


AIM: Use pseudo classes and display link, visited link and active link of contact us
differently.
DESIGN:

CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="hyper.aspx.cs"
Inherits="hyper" %>
<!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>
<style type="text/css">
A:Link{color:Red;}
A:Visited{color:Green;}
A:hover{color:Orange;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default6.aspx">Contact
Us</asp:HyperLink>
</div> </form> </body> </html>

BROWSER OUTPUT:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 51
TYBSC.IT ASP.NET WITH C#

Practical No: 10
AIM: (A) For the web page created for the display OF Employee data change the authentication
mode to Windows
CODE:
<system.web>
<authentication mode=Windows>
<forms loginUrl=~/Prac8/EmployeeForm.aspx>
</authentication>
</system.web
Steps for changing the authentication mode
1. Open the website created for displaying the Employee data
2.From the solution Explorer window open the web.config file
3 .In the web.config file search the <system.web> xml tag and in <system.web> xml tag go to
authentication tag
4. Change the authentication mode to windows as given above.

AIM: (B) For the webpage created for the display of Student data change the authorization mode
so that only users who have logged in as VSIT will have the authority to aces the page
CODE:
<system.web>
<authentication>
<allow users=VSIT/>
<deny users = */>
</authentication>
</system.web>
Steps for changing the authorization
1. Open the website created for displaying the Student data
2. From the solution Explorer window open the web.config file
3. In the Web.config file search the <system.web> xml tag and in <system.web> xml tag go to
authentication tag
4. Change the coding in the tag as given above

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 52
TYBSC.IT ASP.NET WITH C#

Practical No: 1(A)

AIM:- Write a console application that obtains four int values from the
user and displays the product.
CODE:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationsept19
{
class Program
{
static void Main(string[] args)
{
int a, b, c, d, prod;
Console.Write("Enter number 1: ");
a =Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 2: ");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 3: ");
c= Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 4: ");
d = Convert.ToInt32(Console.ReadLine());
prod = a * b * c* d;
Console.WriteLine(a + "*" + b + "*" + c + "*" + d + "=" + prod);

}
}
}

Output:-

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 53
TYBSC.IT ASP.NET WITH C#
Enter number 1: 12
Enter number 2: 45
Enter number 3: 67
Enter number 4: 98
12*45*67*98=3545640
Press any key to continue . . .

Practical No: 1(B)

AIM:- If you have two integers stored in variables var1 and var2, what
Boolean test can you perform to see if one or the other (but not both) is
greater than 10?

CODE:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationsept19
{
class Program
{
static void Main(string[] args)
{
int var1, var2;
Console.Write("Enter number 1: ");
var1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 2: ");
var2 = Convert.ToInt32(Console.ReadLine());
if ((var1 > 10 && var2 <= 10) || (var2 > 10 && var1 <= 10))
{
Console.WriteLine("Boolean test succedded \n Both number are not >10");
}
}
}
}

Output:-
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 54
TYBSC.IT ASP.NET WITH C#

Enter number 1: 3
Enter number 2: 15
Boolean test succedded
Both number are not >10

Press any key to continue . . .

Practical No: 1(C)

AIM:- Write an application that includes the logic from Exercise 1, obtains two numbers from
the user, and displays them, but rejects any input where both numbers are greater than 10 and
asks for two new numbers.
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationsept19
{
class Program
{
static void Main(string[] args)
{
int var1, var2;
label1:
Console.Write("Enter number 1: ");
var1 = Int32.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
var2 = Convert.ToInt32(Console.ReadLine());
if ((var1 > 10 && var2 > 10) )
{
Console.WriteLine("Both No are greater than 10 are not
allowed");
goto label1;
}
else
{
Console.WriteLine("Number 1: "+var1);
Console.WriteLine("Number 2 :"+var2);
} } } }

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 55
TYBSC.IT ASP.NET WITH C#

Output:-
Enter number 1: 56

Enter number 2: 45

Both No are greater than 10 are not allowed

Enter number 1: 1

Enter number 2: 3

Number 1: 1

Number 2 :3

Press any key to continue . . .

Practical No: 1(D)


Aim: Write a console application that places double quotation marks around each word
in a string .

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationsept19
{
class Program
{
static void Main(string[] args)
{
string str1;
Console.Write("Enter string 1: ");
str1 = Console.ReadLine();
string[] words = str1.Split(' ');
foreach (var a in words)
{
Console.WriteLine("\""+a+"\"");

}
}
}
}

Output:

Enter string 1: shi va


NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 56
TYBSC.IT ASP.NET WITH C#

"shi"
"va"
Press any key to continue . . .

Practical No: 1(E)


Aim: Write an application that uses two command-line arguments to place
values into a string and an integer variable, respectively. Then display these
values.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationsept19
{
class Program
{
static void Main(string[] args)
{
string str;
int n;
str = args[0];
n = Convert.ToInt32(args[1]);
Console.WriteLine("strings:" + str);
Console.WriteLine("number:" + n);
Console.ReadKey();

}
}
}

Step before run:


NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 57
TYBSC.IT ASP.NET WITH C#

Project->projectProperties->debug->Command line arguments->type string


and integer
Output:
strings:MITALI
number:3005

Practical No: 1(F)


Aim: Write an application that receives the following information from a set
of students:
Student Id:
Student Name:
Course Name:
Date of Birth:
The application should also display the information of all the students once the
data is Entered. Implement this using an Array of Structures.
Code: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationsept19
{
class Program
{
struct Student
{
public string studid, name, cname;
public int day, month, year;
}

static void Main(string[] args)


{
Student[] s = new Student[5];
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 58
TYBSC.IT ASP.NET WITH C#
int i;
for (i = 0; i < 5; i++)
{
Console.Write("Enter Student Id:");
s[i].studid = Console.ReadLine();
Console.Write("Enter Student name : ");
s[i].name = Console.ReadLine();
Console.Write("Enter Course name : ");
s[i].cname = Console.ReadLine();
Console.Write("Enter date of birth\n Enter day(1-31):");
s[i].day = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter month(1-12):");
s[i].month = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter year:");
s[i].year = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\n\nStudent's List\n");
for (i = 0; i < 5; i++)
{
Console.WriteLine("\nStudent ID : " + s[i].studid);
Console.WriteLine("\nStudent name : " + s[i].name);
Console.WriteLine("\nCourse name : " + s[i].cname);
Console.WriteLine("\nDate of birth(dd-mm-yy) : " + s[i].day + "-" +
s[i].month + "-" + s[i].year);
} } } }
Output:
Enter Student Id:35

Enter Student name : bubbly

Enter Course name : bscit

Enter date of birth

Enter day(1-31):13

Enter month(1-12):7

Enter year:1997

Enter Student Id:305

Enter Student name : mitali

Enter Course name : bscit

Enter date of birth

Enter day(1-31):30

Enter month(1-12):9

Enter year:1997
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 59
TYBSC.IT ASP.NET WITH C#
Enter Student Id:54

Enter Student name : paramjeet

Enter Course name : bscit

Enter date of birth

Enter day(1-31):20

Enter month(1-12):4

Enter year:1997

Enter Student Id:42

Enter Student name : ashwin

Enter Course name : bscit

Enter date of birth

Enter day(1-31):1

Enter month(1-12):6

Enter year:1997

Enter Student Id:69

Enter Student name : arman

Enter Course name : bscit

Enter date of birth

Enter day(1-31):25

Enter month(1-12):5

Enter year:1997

Student's List

Student ID : 35 Student name : bubbly Course name : bscit

Date of birth(dd-mm-yy) : 13-7-1997

Student ID : 3005 Student name : mitali Course name : bscit

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 60
TYBSC.IT ASP.NET WITH C#
Date of birth(dd-mm-yy) : 30-9-1997

Student ID : 54 Student name : paramjeet Course name : bscit

Date of birth(dd-mm-yy) : 20-4-1997

Student ID : 42 Student name : ashwin Course name : bscit

Date of birth(dd-mm-yy) : 1-6-1997

Student ID : 69 Student name : arman Course name : bscit

Date of birth(dd-mm-yy) : 25-5-1997

Press any key to continue . . .

Practical No: 1(G)

Aim: Write programs using conditional statements and


loops: I) Generate Fibonacci series.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(String[] args)
{
int n1 = 0, n2 = 1, n3,n;

Console.Write("Enter a number:");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("\nFibonacci series\n");
Console.Write(n1 + "\t" + n2);
for (int i = 3; i <= n; i++)
{
n3 = n2 + n1;
Console.Write("\t" + n3);
n1 = n2;
n2 = n3;
}

Console.ReadKey();
}}}
Output:

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 61
TYBSC.IT ASP.NET WITH C#
Enter a number:6

Fibonacci series

0 1 1 2 3 5

Practical No:1(H)
Aim: Write programs using conditional statements and loops:Prime Number
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(String[] args)
{

int n, i;
Console.Write("enter a number:");
n = Convert.ToInt32(Console.ReadLine());
for (i = 2; i < n; i++)
{
if ((n % i) == 0)
break;
}
if (i == n)
Console.WriteLine(n + "is prime");
else
Console.WriteLine(n + " is not prime");
Console.ReadKey();

}
}
}

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 62
TYBSC.IT ASP.NET WITH C#

Output:
enter a number:3

3is prime

Practical No:02(1)
AIM: Write a program to declare a class staff having data members as name
andpost.accept this data 5for 5 staffs and display names of staff who are HOD.

CODE:

using System;

namespace staff

class staff

string name, post;

public void getdata()

Console.Write("Enter name and post:");

name = Console.ReadLine();

post = Console.ReadLine();

public void display() {


NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 63
TYBSC.IT ASP.NET WITH C#
Console.WriteLine(name + "\t\t" + post);

public string getPost() {

return post;

} }

class program {

static void Main(string[] args) {

staff[] objStaff = new staff[5];

int i;

for (i = 0; i < 5; i++) {

objStaff[i] = new staff();

objStaff[i].getdata(); }

Console.WriteLine("Name \t\t Post");

for (i = 0; i < 5; i++){

if (objStaff[i].getPost() == "HOD")

objStaff[i].display();

}}}}

OUTPUT:

Enter name and post:Prachit

HOD

Enter name and post:Sumit

PM

Enter name and post:Aniket

HOD

Enter name and post:Prathamesh

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 64
TYBSC.IT ASP.NET WITH C#
PM

Enter name and post:Zaid

CA

Name Post

Prachit HOD

Aniket HOD

Practical No:: 02(2)


AIM: Write a program to declare class Distance have data members dist1,dist2 ,dist3.
Initialize the two data members using constructor and store their addition in third
datamember using function and display addition.

CODE:

using System;

namespace distanceclass

class Distance

int dist1,dist2,dist3;

public Distance(int dist1,int dist2)

this.dist1=dist1;

this.dist2=dist2;

public void addition()

{
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 65
TYBSC.IT ASP.NET WITH C#
dist3=dist1+dist2;

public void display()

Console.WriteLine("Distance1:"+ dist1);

Console.WriteLine("Distance1:"+ dist2);

Console.WriteLine("Distance1:"+ dist3);

}}

class program

static void Main(string[] args)

Distance objDistance = new Distance(10, 20);

objDistance.addition();

objDistance.display();

}}}

OUTPUT:

Distance1:10

Distance1:20

Distance1:30

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 66
TYBSC.IT ASP.NET WITH C#

Practical No:: 02(3)


AIM: Write a program using function overloading to swap two integer numbers and
swap two float numbers.

CODE:

using System;

namespace swap

class Overloading

public void swap(ref int n, ref int m)

int t;

t = n;

n = m;

m = t;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 67
TYBSC.IT ASP.NET WITH C#
public void swap(ref float f1, ref float f2)

float f;

f = f1;

f1 = f2;

f2 = f;

class program

static void Main(string[] args)

Overloading objOverloading = new Overloading();

int n = 10, m = 20;

objOverloading.swap(ref n, ref m);

Console.WriteLine("N=" + n + "\tM=" + m);

float f1 = 10.5f, f2 = 20.6f;

objOverloading.swap(ref f1, ref f2);

Console.WriteLine("F1=" + f1 + "\tF2=" + f2);

}}}

OR
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace swap
{
class Overloading
{
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 68
TYBSC.IT ASP.NET WITH C#
public void swap(ref int n, ref int m)
{
int t;
t = n;
n = m;
m = t;
}
public void swap(ref float f1, ref float f2)
{
float f;
f = f1;
f1 = f2;
f2 = f;
}

}
class program
{
static void Main(string[] args)
{
Overloading obj = new Overloading();
int n, m;
float f1, f2;

Console.Write("enter number 1 ");


n = int.Parse(Console.ReadLine());
Console.Write("enter number 2 ");
m= int.Parse(Console.ReadLine());

Console.Write("enter floating point number 1 ");


f1 = float.Parse(Console.ReadLine());
Console.Write("enter floating point number 2 ");
f2 = float.Parse(Console.ReadLine());
obj.swap(ref n, ref m);
obj.swap(ref f1, ref f2);
Console.WriteLine("\n int numbers after swap");
Console.WriteLine(n + "\t\t" + m);
Console.WriteLine("\n float numbers after swap");
Console.WriteLine(f1 + "\t\t" + f2);
Console.Read();

}
}
}

OUTPUT:

N=20 M=10

F1=20.6 F2=10.5

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 69
TYBSC.IT ASP.NET WITH C#

Practical No:: 02(4)


AIM: Write a program to implement single inheritance from following figure. Accept
and display data for one table.

CODE:

Furniture.cs

using System;

namespace SingleInheritance

class Furniture

string material;

float price;

public void getdata()

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 70
TYBSC.IT ASP.NET WITH C#
Console.Write("Enter material : ");

material = Console.ReadLine();

Console.Write("Enter price : ");

price = float.Parse(Console.ReadLine());

public void showdata()

Console.WriteLine("Material : " + material);

Console.WriteLine("Price : " + price);

}}}

Table.cs

using System;

namespace SingleInheritance

class Table:Furniture

int height, surface_area;

public void getdata()

base.getdata();

Console.Write("Enter height: ");

height = int.Parse(Console.ReadLine());

Console.Write("Enter surface area: ");

Class Furniture

Data Members : material ,price

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 71
TYBSC.IT ASP.NET WITH C#
Class Table

Data Members : Height ,surface_area

surface_area = int.Parse(Console.ReadLine());

public void showdata()

base.showdata();

Console.WriteLine("Height : " + height);

Console.WriteLine("Surface Area : " + surface_area);

}}}

Program.cs

using System;

namespace SingleInheritance

class Program

static void Main(string[] args)

Table t1 = new Table();

t1.getdata();

t1.showdata();

}}}

Or
using System;
using System.Collections.Generic;
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 72
TYBSC.IT ASP.NET WITH C#
using System.Linq;
using System.Text;

namespace swap
{
class Furniture
{
string material;
float price;
public void getData()
{
Console.Write("enter the type of material");
material = Console.ReadLine();
Console.Write("enter price:");
price = float.Parse(Console.ReadLine());
}
public void showData()
{
Console.Write("material: " + material);
Console.Write("price: " + price);

}
}

class Table:Furniture
{
float height, surface_area;
public void getData()
{
base.getData();
Console.Write("enter the type of height");
height = float.Parse(Console.ReadLine());
Console.Write("enter surface area:");
surface_area = float.Parse(Console.ReadLine());
}
public void showData()
{
base.showData();
Console.Write("height: " + height);
Console.Write("surface area: " + surface_area);

class program
{
static void Main(string[] args)
{
Table t = new Table();
t.getData();
t.showData();
Console.Read();

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 73
TYBSC.IT ASP.NET WITH C#

}
}
}

OUTPUT:

Enter material : wood

Enter price : 1220

Enter height: 35

Enter surface area: 26

Material : wood

Price : 1220

Height : 35

Surface Area : 26

Practical No:: 02(5)


AIM: Define a class salary which will contain member variable Basic, TA, DA,
HRA.Write a program using Constructor with default values for DA and HRA and
calculate the salary of employee.

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
class Salary
{
NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 74
TYBSC.IT ASP.NET WITH C#
int basic, ta, da, hra;
public Salary()
{
da = 9000;
hra = 6000;
}
public void getdata()
{
Console.Write("Enter basic salary : ");
basic = int.Parse(Console.ReadLine());
Console.Write("Enter travelling allowance : ");
ta = int.Parse(Console.ReadLine());
}
public void showdata()
{
Console.WriteLine("Basic salary : " + basic);
Console.WriteLine("Dearness allowence : " + da);
Console.WriteLine("Housing rent allowence : " + hra);
Console.WriteLine("Travelling allowence : " + ta);
Console.WriteLine("Gross Salary : " + (basic + da + hra + ta));
} }
class Program
{
static void Main(string[] args)
{
Salary s = new Salary();
s.getdata();
s.showdata();
Console.Read();
}
}
}

OUTPUT:

Enter basic salary : 52000

Enter travelling allowance : 3000

Basic salary : 52000

Dearness allowence : 9000

Housing rent allowence : 6000

Travelling allowence : 3000

Gross Salary : 70000

Practical No:: 02(6)


AIM: Program to implement the following multiple inheritance using interface.

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 75
TYBSC.IT ASP.NET WITH C#
CODE:

Gross.cs

using System;

namespace MultipleInheritance

interface Gross

int ta

get;

set;

int da

get;

set;

int GrossSal();

}}

Employee.cs

using System;

namespace MultipleInheritance

class Employee

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 76
TYBSC.IT ASP.NET WITH C#
string name;

public Employee(string name)

{ this.name = name; }

public int BasicSal(int basicSal)

{ return basicSal; }

public void ShowData()

Console.WriteLine("Name : " + name);

}}}

Salary.cs

Interface: Gross

TA,DA ,Gross_sal()

Class : Employee

name, basic_sal()

Class : salary

Disp_sal(),HRA

using System;

namespace MultipleInheritance

class Salary:employee,Gross

int hra;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 77
TYBSC.IT ASP.NET WITH C#
public Salary(string name, int hra):base(name)

{ this.hra = hra; }

public int ta

get {return S_ta; }

set { S_ta = value; }

private int S_ta;

public int da

get { return S_da; }

set { S_da = value; }

private int S_da;

public int GrossSal() {

int gSal;

gSal = hra + ta + da + BasicSal(15000);

return gSal;

public void dispSal()

{ base.ShowData();

Console.WriteLine("Gross Sal : " + GrossSal());

}}}

Program.cs

using System;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 78
TYBSC.IT ASP.NET WITH C#
namespace MultipleInheritance

class Program

static void Main(string[] args)

Salary s = new Salary("Prachit", 35000);

s.da = 20000;

s.ta = 30000;

s.dispSal();

}}}

OUTPUT:

Name :Prachit

Gross Sal :100000

Practical No: : 02(7)

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 79
TYBSC.IT ASP.NET WITH C#
AIM: Write a program for above class hierarchy for the Employee where the base class
is Employee and derived class and Programmer and Manager. Here make display
function virtual which is common for all and which will display information of
Programmer and Manager interactively.

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System;
namespace HeirarchicalInheritance
{
class employee
{
public virtual void display()
{
Console.WriteLine("Display of employee class called ");
}
}
class Programmer : employee
{
public void display()
{
Console.WriteLine(" Display of Programmer class called ");
}
}

class Manager : employee


{
public void display()
{
Console.WriteLine("Display of manager class called ");
}
}
class Program
{
static void Main(string[] args)
{
Programmer objProgrammer;
Manager objManager;
Console.Write("Whose details you want to use to see \n 1.Programmer
\n2.Manager");
int choice = int.Parse(Console.ReadLine());
if (choice == 1)
{
objProgrammer = new Programmer();
objProgrammer.display();
}
else if (choice == 2)
{
objManager = new Manager();
objManager.display();
}

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 80
TYBSC.IT ASP.NET WITH C#
else
{
Console.WriteLine("Wrong choice entered");
}
Console.Read();
}
}
}

OUTPUT:

Whose details you want to use to see

1.Programmer

2.Manager1

Display of Programmer class called

Whose details you want to use to see

1.Programmer

2.Manager2

Display of manager class called

Whose details you want to use to see

1.Programmer

2.Manager6

Wrong choice entered

Practical No:: 02(8)


AIM: Write a program to implement multilevel inheritance from following figure.
Accept and display data for one student.

CODE:

Result.cs

using System;

namespace multilevelinheritance

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 81
TYBSC.IT ASP.NET WITH C#
{

class Result:Test

int total;

public Result(int roll_no, string name, int marks1, int marks2)

: base(roll_no, name, marks1, marks2)

total = getMarks1() + getMarks2();

public void display()

base.display();

Console.WriteLine("Total: " + total);

}}}

Test.cs

using System;

namespace multilevelinheritance

class Test:student

int marks1, marks2;

public Test(int roll_no, string name, int marks1, int marks2)

: base(roll_no, name)

this.marks1 = marks1;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 82
TYBSC.IT ASP.NET WITH C#
this.marks2 = marks2;

Class student

Data Members : Roll_no , name

Class Test

Data Members : marks1 , marks2

Class Result

Data Members : total

public int getMarks1()

return marks1;

public int getMarks2()

return marks2;

public void dispaly()

base.display();

Console.WriteLine("Marks1: " + marks1);

Console.WriteLine("Marks2: " + marks2);

}}}

Student.cs

using System;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 83
TYBSC.IT ASP.NET WITH C#
namespace multilevelinheritance

class student

int roll_no;

string name;

public student(int roll_no, string name)

this.roll_no = roll_no;

this.name = name;

public student() { }

public void display()

Console.WriteLine("Roll no: " + roll_no);

Console.WriteLine("Name: " + name);

}}}

Program.cs

using System;

namespace multilevelinheritance

class Program

static void Main(string[] args)

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 84
TYBSC.IT ASP.NET WITH C#
{

Result r1 = new Result(101, "Prachit", 50, 70);

r1.display();

}}}

OUTPUT:

Roll no: 101

Name: Prachit

Marks1: 50

Marks2: 70

Total: 120

Practical No:: 02(9)


AIM: Write a program to create a delegate called TrafficDel and a class called
TrafficSignal with the following delegate methods.

Public static void Yellow()

Console.WriteLine(Yellow Light Signal To Get Ready);

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 85
TYBSC.IT ASP.NET WITH C#
Public static void Green()

Console.WriteLine(Green Light Signal To Go);

Public static void Red()

Console.WriteLine(Red Light Signal To Stop);

Also include a method IdentifySignal() to initialize an array of delegate with the


abovemethods and a method show() to invoke members of the above array.

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
public delegate void TrafficDel();
class TrafficSignal
{
public static void Yellow()
{
Console.WriteLine("Yellow light signals to get ready");
}
public static void Green()
{
Console.WriteLine("Green light signals to go");
}
public static void Red()
{
Console.WriteLine("Red light signals to stop");
}
TrafficDel[] td = new TrafficDel[3];
public void IdentifySignal()
{
td[0] = new TrafficDel(Yellow);
td[1] = new TrafficDel(Green);
td[2] = new TrafficDel(Red);
}
public void display()
{
td[0]();
td[1]();

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 86
TYBSC.IT ASP.NET WITH C#
td[2]();
}
}
class Program
{
static void Main(string[] args)
{
TrafficSignal ts = new TrafficSignal();
ts.IdentifySignal();
ts.display();
Console.Read();
} } }

OUTPUT:

Yellow light signals to get ready

Green light signals to go

Red light signals to stop

Practical No:: 02(10)


AIM: Write a program to accept a number from the user and throw an exception if
thenumber is not an even number.

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 87
TYBSC.IT ASP.NET WITH C#
namespace ConsoleApplication3
{
class NotEvenException:Exception
{
public NotEvenException(string msg)
: base(msg)
{
}
}
class Program
{
static void Main(string[] args)
{
int num;
try
{
Console.Write("Enter a number: ");
num = int.Parse(Console.ReadLine());
if ((num % 2) != 0) throw new NotEvenException("Not an even number ");
else
Console.WriteLine("Its even number ");
}
catch (NotEvenException e) { Console.WriteLine(e.Message); }
Console.Read();
} } }

OUTPUT:

Enter a number: 5

Not an even number

Enter a number: 6

Its even number

NAME:MITALI CHITRE ROLLNO:16302C3005

Page | 88

S-ar putea să vă placă și