66
Page.1 Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) HEMCHANDRACHARYA NORTH GUJARAT UNIVERSITY, PATAN B.C.A. Semester – V BCA-506 : .NET Frame Work Using C# Teaching Scheme (per week) Teaching Scheme (per semester) Examination Scheme INT EXT TOTAL Th. (hours) Pr. (hours) Total Hours Credit Th. (marks) Pr. (marks) Th. (marks) Pr. (marks) Th. (marks) Pr. (marks) -- 4 40 4 -- 30 -- 70 -- 100 University Examination Duration: 3 Hours (Per Batch) (Practical List) 1. Write the Steps for configure IIS with Asp.Net 2. Write an Asp.Net Program to print a Message on web form. 3. Write an Asp.Net Program to Create Simple Web Application using two or more web form. 4. Write an Asp.Net Program to set a link for new Page. 5. Write an Asp.Net program using different namespaces. 6. Write an Asp.Net Program to demonstrate different common Control. 7. Write an Asp.Net Program to demonstrate Request, Response and Server Object. 8. Write a program using delegation in which addition and subtraction of two integer value possible. 9. Write an Asp.Net program using while or for loop to print sum of first 100 ODD and Even Numbers. 10.Write an Asp.Net Program to add the value of Text Box in to Dropdown List and List box Controls. 11.Write an Asp.Net Program to Delete Items from Dropdown list and List box. 12.Write an Asp.Net Program to set Image on Image Control according to selection of image name from dropdown list. 13.Write an Asp.Net Program to demonstrate use of Master Page using Themes. 14.Write an Asp.Net Program to perform Insert and update operation in Database. 15.Write an Asp.Net program to perform Search and Delete operation in Database. 16.Write an Asp.net program to display the records from database using Data Reader Object. 17.Write an Asp.Net Program to demonstrate the various methods of Dataset Object. 18.Write an Asp.Net Program to demonstrate Login Page using Database. Practical Exam Scheme: Program Output Viva Journal Total 25 Marks 15 Marks 20 Marks 10 Marks 70 Marks

Bca sem 5 c# practical

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Bca sem 5 c# practical

 

 Page. 1                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

HEMCHANDRACHARYA NORTH GUJARAT UNIVERSITY, PATAN B.C.A. Semester – V

BCA-506 : .NET Frame Work Using C#

Teaching Scheme (per

week)

Teaching Scheme (per

semester)

Examination Scheme

INT EXT TOTAL

Th. (hours)

Pr. (hours)

Total Hours Credit Th.

(marks)Pr.

(marks)Th.

(marks)Pr.

(marks) Th.

(marks)Pr.

(marks)

-- 4 40 4 -- 30 -- 70 -- 100

University Examination Duration: 3 Hours (Per Batch)

(Practical List)

1. Write the Steps for configure IIS with Asp.Net 2. Write an Asp.Net Program to print a Message on web form. 3. Write an Asp.Net Program to Create Simple Web Application using two or more web form. 4. Write an Asp.Net Program to set a link for new Page. 5. Write an Asp.Net program using different namespaces. 6. Write an Asp.Net Program to demonstrate different common Control. 7. Write an Asp.Net Program to demonstrate Request, Response and Server Object. 8. Write a program using delegation in which addition and subtraction of two integer value

possible. 9. Write an Asp.Net program using while or for loop to print sum of first 100 ODD and Even

Numbers. 10.Write an Asp.Net Program to add the value of Text Box in to Dropdown List and List box

Controls. 11.Write an Asp.Net Program to Delete Items from Dropdown list and List box. 12.Write an Asp.Net Program to set Image on Image Control according to selection of image

name from dropdown list. 13.Write an Asp.Net Program to demonstrate use of Master Page using Themes. 14.Write an Asp.Net Program to perform Insert and update operation in Database. 15.Write an Asp.Net program to perform Search and Delete operation in Database. 16.Write an Asp.net program to display the records from database using Data Reader

Object. 17.Write an Asp.Net Program to demonstrate the various methods of Dataset Object. 18.Write an Asp.Net Program to demonstrate Login Page using Database.

Practical Exam Scheme:

Program Output Viva Journal Total

25 Marks 15 Marks 20 Marks 10 Marks 70 Marks

Page 2: Bca sem 5 c# practical

 

 Page. 2                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 1 - Write the Steps for configure IIS with Asp.Net

Installation of IIS in Windows XP

Windows XP does not generally have IIS installed by default, so it will probably have to be done manually. To do so, follow these steps:

Step: 1 – Click on Start Button → Go to Control Panel, and open Add/Remove Programs.

Step: 2 – In the left side panel, click on Add/Remove Windows Components.

Page 3: Bca sem 5 c# practical

 

 Page. 3                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step: 3 – In the window Components Wizard, find the 'Internet Information Services (IIS)' option and check it.

Step: 4 – Click on "Details" button. Ensure that 'World Wide Web Service' is checked. Select other options as per your need and then click "OK".

Page 4: Bca sem 5 c# practical

 

 Page. 4                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step: 5 - Click on "Next" Button, the required files will begin to copy. we may be prompted to insert the original Windows XP install CD, if we have not given windows XP Installation disc or installation source.

Step: 6 - Once the file copy is complete, click "Finish".

Page 5: Bca sem 5 c# practical

 

 Page. 5                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Now, In Control Panel, open 'Administrative Tools' and IIS should now be installed.

How to test IIS (Web Server) is successfully installed or not? Open Web Browser and type http://localhost in the Address Bar. If web browser shows the information about your IIS, then your web server (IIS) installed successfully.

Installation of IIS in Windows Vista and Windows 7 Step: 1 – Click on Start Button → Go to Control Panel.

Step: 2 – In the Control Panel click on programs or in the left side panel, select Classic View and Open Programs and Features.

Page 6: Bca sem 5 c# practical

 

 Page. 6                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Or

Step: 3 – In the left side panel, click on “Turn Windows features on or off” link. Or click on “turn on or off windows features”.

Step: 4 - You may receive the Windows Security warning. Click Allow to continue. The Windows Features dialog box is displayed.

Step: 5 - Expand Internet Information Services. Additional categories of IIS features are displayed. Select Internet Information Services to choose the default features for installation. Expand the additional categories displayed, and select any additional features we want to install, such as Web Management Tools, FTP etc.

Page 7: Bca sem 5 c# practical

 

 Page. 7                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step: 6 – Click “OK” button at the bottom, and wait for installation to complete.

Page 8: Bca sem 5 c# practical

 

 Page. 8                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

IIS is now installed with a default configuration on Windows Vista or Windows 7.

Next, you can use Internet Information Services Manager to manage and configure IIS. To open IIS Manager, click Start, type inetmgr in the Search Programs and Files box, and then press ENTER.

Installation of IIS on Windows 8 Step: 1 - Press the Windows + R key combination to bring up a run box, then type appwiz.cpl and press ok or press enter.

Step: 2 - This will open the Program and Features part of Control Panel, on the left hand side click on the “Turn Windows features on or off” link.

Page 9: Bca sem 5 c# practical

 

 Page. 9                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step: 3 - Now click on the Internet Information Services check box. Select other options as per your need and then click "OK".

Step: 4 - Click “OK” button at the bottom, and wait for installation to complete.

Page 10: Bca sem 5 c# practical

 

 Page. 10                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

How to test IIS (Web Server) is successfully installed or not. Open Web Browser and type http://localhost in the Address Bar. If web browser shows the information about your IIS, then your web server (IIS) installed successfully.

IIS 8 Successfully Installed on Windows 8. Practical: 2 - Write an Asp.Net Program to print a Message on web form. Practical_2.aspx <html> <head runat="server"> <title>Practical_2 Print a Message</title> </head> <body> <form id="form1" runat="server"> <div> <i>Hello. This is your Practical-2 (Message from Source (.aspx))</i> </div> </form> </body> </html>

Page 11: Bca sem 5 c# practical

 

 Page. 11                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical_2.aspx.cs protected void Page_Load(object sender, EventArgs e) { string message = "This is your Practical-2 (Message from Code Behind

(.aspx.cs)->Variable)"; Response.Write("Hello. This is your Practical-2 (Message from

Code Behind (.aspx.cs))<br />"); Response.Write(message); Response.Write("<br />"); Response.Write("<b>" + message + "</b>"); } Output

   

Practical: 3 - Write an Asp.Net Program to Create Simple Web Application using two or more web form. Code: Practical-3.aspx <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>My Home Page</title> <link href="webcss.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <table border="0" cellspacing="0" bordercolor="#FF6633" width="900px" align="center"> <tr> <td align="center"><img src="hponline.png" width="889px" /></td> </tr> <tr>

Page 12: Bca sem 5 c# practical

 

 Page. 12                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

<td><hr></td> </tr> <tr> <td align="center"><b>|| <asp:LinkButton ID="lnkhome" runat="server" onclick="lnkhome_Click"> <b>Home</b></asp:LinkButton> &nbsp;|| <asp:HyperLink ID="hlink1" runat="server" NavigateUrl="~/practical-10.aspx" Target="_blank"><b>Practical-10</b></asp:HyperLink> &nbsp;|| <asp:HyperLink ID="hlink2" runat="server" NavigateUrl="~/practical-11.aspx"><b>Practical-11</b></asp:HyperLink> &nbsp;||</b></td> </tr> <tr> <td><hr></td> </tr> <tr> <td align="center"><h1><asp:Label ID="lbltitle" runat="server" Text="Label"></asp:Label> </h1><br> <asp:Image ID="Image1" runat="server" /> </td> </tr> <tr> <td><hr></td> </tr> <tr> <td align="center"><b>Copyright &copy; abcxyz.com</b></td> </tr> <tr> <td><hr></td> </tr> </table> </form> </body> </html> Code: Practical-3.aspx.cs protected void Page_Load(object sender, EventArgs e) { Image1.ImageUrl = "~/avatar.png"; lbltitle.Text = "Welcome to My Web Application..."; } protected void lnkhome_Click(object sender, EventArgs e) { lnkhome.PostBackUrl = "~/default.aspx";

Page 13: Bca sem 5 c# practical

 

 Page. 13                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

} Code: webcss.css body { background-color:#09C; background-image:url(bgimage.png); background-attachment:fixed; background-repeat:no-repeat; background-position:left center; } h1 { color:yellow; font-size:24px; font-family:Georgia, "Times New Roman", Times, serif; text-shadow:#003 3px 3px 3px; } p { text-align:justify; line-height:20px; } Output:

Page 14: Bca sem 5 c# practical

 

 Page. 14                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 4 - Write an Asp.Net Program to set a link for new Page. Practical_4.aspx : Code <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <a href="Default.aspx" target="_blank">Click here to go "Home Page"

using Anchor (a) Tag</a> <br /> <asp:LinkButton ID="lnkhomepage" runat="server" OnClick="lnkhomepage_Click">

Home Page using Link Button</asp:LinkButton><br /> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx"

Target="_blank">HyperLink</asp:HyperLink> <br /> <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="ImageButtonText" Height="44px" ImageUrl="~/btnhome.jpg" onclick="ImageButton1_Click" Width="111px" /> </div> </form> </body> </html> Practical_4.aspx.cs : Code public partial class practical_4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void lnkhomepage_Click(object sender, EventArgs e) { if (IsPostBack) { Response.Write("<script>alert('Postback');</script>"); lnkhomepage.PostBackUrl = "~/default.aspx"; } } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { if (IsPostBack) { Response.Write("<script>alert('Postback');</script>"); ImageButton1.PostBackUrl = "~/default.aspx"; }

Page 15: Bca sem 5 c# practical

 

 Page. 15                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

} }

Output:

  

 

Page 16: Bca sem 5 c# practical

 

 Page. 16                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 5 - Write an Asp.Net program using different namespaces. First add a class file. Right click on your web application from the solution explorer, click on add new item Now we can see ‘add new item’ window. Select class and type the name of your file then click on add button.

Now create your own custom namespace and class in the class file. simplenm.cs using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public class simplenm { public string simplenmclsfun() { return "<b>WELCOME TO your simplenm class. message return from

simplenmclsfun() function.</b>" + "<br />"; } }

Page 17: Bca sem 5 c# practical

 

 Page. 17                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

namespace basiccalc { public class msgclass { public static string msgfun() { return "<b>WELCOME TO CUSTOME NAMESPACE. message return from

msgfun()&nbsp;</b>" + "<br />"; } } public class calc { public static int sum(int val1, int val2) { int getval1, getval2,sum; getval1 = val1; getval2 = val2; sum = getval1 + getval2; return sum; } public static int sub(int val1, int val2) { int getval1, getval2, sub; getval1 = val1; getval2 = val2; sub = getval1 - getval2; return sub; } public static int mul(int val1, int val2) { int getval1, getval2, mul; getval1 = val1; getval2 = val2; mul = getval1 * getval2; return mul; } public static int div(int val1, int val2) { int getval1, getval2, div; getval1 = val1; getval2 = val2; div = getval1 / getval2; return div; } } }

Page 18: Bca sem 5 c# practical

 

 Page. 18                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Default.aspx.cs using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; // add your name space here to access all class and its memers functions. using basiccalc; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // create clsmsgobj object to access simplenm class and its members. simplenm clsmsgobj = new simplenm(); string clsmsg = clsmsgobj.simplenmclsfun(); Response.Write(clsmsg); //msgclass is the created under the basiccalc namespace. msgfun() is the

member of msgclass string getnmsg = msgclass.msgfun(); Response.Write(getnmsg); int val1 = 50, val2 = 2; Response.Write("Value of val1 is:" + val1 + ", Value of val2 is:" + val2 + "<br>"); //access functions from the calc class under the basiccalc namespace. int sum = calc.sum(val1, val2); int sub = calc.sub(val1, val2); int mul = calc.mul(val1, val2); int div = calc.div(val1, val2); Response.Write("Sum is: " + sum + "<br>"); Response.Write("Subtraction is: " + sub + "<br>"); Response.Write("Multiplication is: " + mul + "<br>"); Response.Write("Division is: " + div + "<br>"); } }

Page 19: Bca sem 5 c# practical

 

 Page. 19                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Output: WELCOME TO your simplenm class. message return from simplenmclsfun() function. WELCOME TO CUSTOME NAMESPACE. message return from msgfun() Value of val1 is:50, Value of val2 is:2 Sum is: 52 Subtraction is: 48 Multiplication is: 100 Division is: 25 Practical: 6 - Write an Asp.Net Program to demonstrate different common Control. Code: Practical-6.aspx <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> Demostration of Different Common Controls...........<br /> Label Control: <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> TextBox Control: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> Literal Control: <asp:Literal ID="Literal1" runat="server"></asp:Literal> <br /> Button Control: <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click Me" /> <br /> Link Botton Control: <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Click here to go HOME PAGE</asp:LinkButton> <br /> Image Button Control: <asp:ImageButton ID="ImageButton1" runat="server" onclick="ImageButton1_Click" /> <br /> List Box Control: <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" onselectedindexchanged="ListBox1_SelectedIndexChanged"></asp:ListBox> <br /> Drop Down List Control: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged">

Page 20: Bca sem 5 c# practical

 

 Page. 20                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

</asp:DropDownList> <br /> Checkbox Control: <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="Tea" Checked="True" /> <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Text="Cofee" /> <asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" Text="Burger" /> <br /> Radio Button Control: <asp:RadioButton ID="RadioButton1" runat="server" oncheckedchanged="age_CheckedChanged" Text="10-25" AutoPostBack="True" /> <asp:RadioButton ID="RadioButton2" runat="server" Checked="True" oncheckedchanged="age_CheckedChanged" Text="26-50" AutoPostBack="True" /> <asp:RadioButton ID="RadioButton3" runat="server" oncheckedchanged="age_CheckedChanged" Text="51-75" AutoPostBack="True" /> <br /> Image Control:<br /> &nbsp;<asp:Image ID="Image1" runat="server" /> <br /> Bulleted Control: <asp:BulletedList ID="BulletedList1" runat="server" Width="87px"> </asp:BulletedList> <br /> Hidden Field Control:<asp:HiddenField ID="HiddenField1" runat="server" Value="This is HiddenField Value" /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <br /> <br /> Calender Control:<br /> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> <asp:Calendar ID="Calendar1" runat="server" onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar> <br /> Table Control; <asp:Table ID="Table1" runat="server" BackImageUrl="~/friends.jpg" BorderColor="#009933" BorderStyle="Double" BorderWidth="4px" CellPadding="3" CellSpacing="3" Font-Bold="True" Font-Size="40pt" GridLines="Both" Height="200px" Width="300px"> <asp:TableRow runat="server"> <asp:TableCell runat="server">1</asp:TableCell> <asp:TableCell runat="server">2</asp:TableCell> <asp:TableCell runat="server">3</asp:TableCell> </asp:TableRow> <asp:TableRow runat="server"> <asp:TableCell runat="server">4</asp:TableCell> <asp:TableCell runat="server">5</asp:TableCell> <asp:TableCell runat="server">6</asp:TableCell> </asp:TableRow> </asp:Table> &nbsp;<br />

Page 21: Bca sem 5 c# practical

 

 Page. 21                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Image Map Control:<br /> <asp:ImageMap ID="ImageMap1" runat="server" HotSpotMode="Navigate" ImageUrl="~/avatar.png"> <asp:CircleHotSpot AlternateText="50X50" NavigateUrl="~/Default.aspx" Radius="30" Target="_blank" X="50" Y="50" /> <asp:RectangleHotSpot AlternateText="hello" Bottom="30" Left="50" Right="5" Top="30" /> </asp:ImageMap> <br /> Panel Control:<br /> <asp:Panel ID="Panel1" runat="server" GroupingText="Panel Control" ScrollBars="Both"> You are in Panel Control... </asp:Panel> </form> </body> </html> Code: Practical-6.aspx.cs protected void Page_Load(object sender, EventArgs e) { Literal1.Text = "<b>Literal Control</b>"; Label1.Text = "Label Control"; Label2.Text = HiddenField1.Value; RadioButton1.GroupName = "age"; RadioButton2.GroupName = "age"; RadioButton3.GroupName = "age"; ImageButton1.ImageUrl = "~/btnhome.jpg"; Image1.ImageUrl = "~/friends.jpg"; if (CheckBox1.Checked == true) { Label1.Text = "Tea selected"; } if (CheckBox2.Checked == true) { Label1.Text = "Coffee selected"; } if (CheckBox3.Checked == true) { Label1.Text = "Burger selected"; } if (!IsPostBack) {

Page 22: Bca sem 5 c# practical

 

 Page. 22                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

BulletedList1.Items.Add("Bullet List1"); BulletedList1.Items.Add("Bullet List2"); BulletedList1.Items.Add("Bullet List3"); BulletedList1.Items.Add("Bullet List4"); BulletedList1.Items.Add("Bullet List5"); ListBox1.Items.Add("List Item1"); ListBox1.Items.Add("List Item2"); ListBox1.Items.Add("List Item3"); ListBox1.Items.Add("List Item4"); ListBox1.Items.Add("List Item5"); DropDownList1.Items.Add("Dropdownlist Item1"); DropDownList1.Items.Add("Dropdownlist Item2"); DropDownList1.Items.Add("Dropdownlist Item3"); DropDownList1.Items.Add("Dropdownlist Item4"); DropDownList1.Items.Add("Dropdownlist Item5"); } } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = TextBox1.Text; Literal1.Text = TextBox1.Text; } protected void LinkButton1_Click(object sender, EventArgs e) { LinkButton1.PostBackUrl = "~/Default.aspx"; } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { ImageButton1.PostBackUrl = "~/Default.aspx"; } protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = ListBox1.SelectedItem.ToString(); Literal1.Text = ListBox1.SelectedItem.ToString(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = DropDownList1.SelectedItem.ToString(); Literal1.Text = DropDownList1.SelectedItem.ToString(); } protected void age_CheckedChanged(object sender, EventArgs e) { if (RadioButton1.Checked == true) { Label1.Text = "My age between 10-25 years"; } else if (RadioButton2.Checked == true) {

Page 23: Bca sem 5 c# practical

 

 Page. 23                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Label1.Text = "My age between 26-50 years"; } else if (RadioButton3.Checked == true) { Label1.Text = "My age between 51-75 years"; } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { Label3.Text = Calendar1.SelectedDate.ToShortDateString(); } Output:

   

Page 24: Bca sem 5 c# practical

 

 Page. 24                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 7 - Write an Asp.Net Program to demonstrate Request, Response and Server Object. Code: practical-7.aspx.cs (server object) protected void Page_Load(object sender, EventArgs e) { //Server Object Server.ScriptTimeout = 500; //default value is 90 seconds Response.Write("Script will be terminated after: " + Server.ScriptTimeout + " Second

from the server.<br>"); Response.Write("You are in Practical-7<br>"); Server.Execute("default.aspx"); Response.Write("You are in Practical-7!<br>"); Response.Write(Server.MapPath("default.aspx") + "<br>"); Response.Write(Server.MapPath("gallery/1.jpg") + "<br>"); Response.Write(Server.MapPath("~/gallery/5.jpg") + "<br>"); Response.Write(Server.MapPath("~/") + "<br>"); string url = Server.UrlEncode("http://www.google.com/images/about.aspx"); Response.Write(url + "<br>"); url = Server.UrlDecode(url); Response.Write(url + "<br>"); Response.Write("Line 1 in File 1<br>"); Server.Transfer("default.aspx"); Response.Write("Line 2 in File 1<br>"); }

Output:

 

Page 25: Bca sem 5 c# practical

 

 Page. 25                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

 

Code: practical-71.aspx <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="google.com" onclick="Button1_Click" /> <br /> <br /> <asp:TextBox ID="txtname" runat="server" Width="191px"></asp:TextBox> <br /> <asp:Button ID="btnsubmit" runat="server" Text="Pass data using query string" onclick="btnsubmit_Click" Width="191px" /> <br /> <asp:Button ID="btncookie" runat="server" Text="set cookie" onclick="btncookie_Click" /> <asp:Button ID="btnsession" runat="server" Text="set session" onclick="btnsession_Click" /> <br /> <asp:Button ID="btnapp" runat="server" Text="using application var" onclick="btnapp_Click" Width="191px" /> <br /> </div> </form> </body> </html> Code: practical-71.aspx.cs protected void Page_Load(object sender, EventArgs e) { //Response Object HttpCookie userCookie; userCookie = Request.Cookies["UserID"]; if (userCookie == null) { Label1.Text = "Cookie doesn't exist! Creating a cookie now."; userCookie = new HttpCookie("UserID", "HP"); userCookie.Expires = DateTime.Now.AddMonths(1); Response.Cookies.Add(userCookie); } else {

Page 26: Bca sem 5 c# practical

 

 Page. 26                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Label1.Text = "Welcome back, " + userCookie.Value; } string name="response.write object here"; Response.Write(name); } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("http://www.google.com"); } protected void btnsubmit_Click(object sender, EventArgs e) { Response.Redirect("practical-72.aspx?txtname=" + txtname.Text); } protected void btncookie_Click(object sender, EventArgs e) { HttpCookie cName = new HttpCookie("Name"); cName.Value = txtname.Text; Response.Cookies.Add(cName); //Response.Redirect("practical-72.aspx"); } protected void btnsession_Click(object sender, EventArgs e) { Session["Name"] = txtname.Text; //Response.Redirect("practical-72.aspx"); } protected void btnapp_Click(object sender, EventArgs e) { Application["Name"] = txtname.Text; //Response.Redirect("practical-72.aspx"); } Output:

 

Page 27: Bca sem 5 c# practical

 

 Page. 27                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Code: practical-72.aspx  

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> using Query string: <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> Using cookie: <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <br /> Using Session: <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> <br /> Using Application var: <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>

Code: practical-72.aspx.cs

protected void Page_Load(object sender, EventArgs e) { //Request Object Response.Write("<B>all http header: </B>" + HttpContext.Current.Request.ServerVariables["ALL_HTTP"] + "<BR>"); Response.Write("<B>appl physical path: </B>" + HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "<BR>"); Response.Write("<B>auth type: </B>" + HttpContext.Current.Request.ServerVariables["AUTH_TYPE"] + "<BR>"); Response.Write("<B>auth user: </B>" + HttpContext.Current.Request.ServerVariables["AUTH_USER"] + "<BR>"); Response.Write("<B>accept language: </B>" + HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"] + "<BR>"); Response.Write("<B>browser information: </B>" + HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"] + "<BR>"); Response.Write("<B>http Cookie: </B>" + HttpContext.Current.Request.ServerVariables["HTTP_COOKIE"] + "<BR>"); Response.Write("<B>Local Address: </B>" + HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"] + "<BR>"); Response.Write("<B>Path information: </B>" + HttpContext.Current.Request.ServerVariables["PATH_INFO"] + "<BR>");

Page 28: Bca sem 5 c# practical

 

 Page. 28                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Response.Write("<B>Query String: </B>" + HttpContext.Current.Request.ServerVariables["QUERY_STRING"] + "<BR>"); Response.Write("<B>Remote Address: </B>" + HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] + "<BR>"); Response.Write("<B>Remote Host: </B>" + HttpContext.Current.Request.ServerVariables["REMOTE_HOST"] + "<BR>"); Response.Write("<B>Remote User: </B>" + HttpContext.Current.Request.ServerVariables["REMOTE_USER"] + "<BR>"); Response.Write("<B>Request Method: </B>" + HttpContext.Current.Request.ServerVariables["REQUEST_METHOD"] + "<BR>"); Response.Write("<B>Script Name: </B>" + HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"] + "<BR>"); Response.Write("<B>Server Name: </B>" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "<BR>"); Response.Write("<B>Server port: </B>" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"] + "<BR>"); Response.Write("<B>Server port is Secure?(y-1,n-0): </B>" + HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"] + "<BR>"); Response.Write("<B>The name and revision of the request information protocol IS: </B>" + HttpContext.Current.Request.ServerVariables["SERVER_PROTOCOL"] + "<BR>"); Response.Write("<B>URL IS: </B>" + HttpContext.Current.Request.ServerVariables["URL"] + "<BR>"); Label1.Text = Request.QueryString["txtname"]; if (Request.Cookies["Name"] != null) Label2.Text = Request.Cookies["Name"].Value; if (Session["Name"] != null) Label3.Text = Session["Name"].ToString(); if (Application["Name"] != null) Label4.Text = Application["Name"].ToString(); }

Page 29: Bca sem 5 c# practical

 

 Page. 29                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Output:

Page 30: Bca sem 5 c# practical

 

 Page. 30                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 8 - Write a program using delegation in which addition and subtraction of two integer value possible. Delegate Example 1: Code: delegate void Mdelegate1(); delegate string Mdelegate2(); public partial class practical_81 : System.Web.UI.Page { public void Callback1() // Does not return the value { Response.Write("Calling callback1 <br>"); } public string Callback2() // Return the Value { return "Calling callback2"; } protected void Page_Load(object sender, EventArgs e) { Mdelegate1 del1 = new Mdelegate1(Callback1); del1(); Mdelegate2 del2 = new Mdelegate2(Callback2); Response.Write(del2()); } }

Output:  

Page 31: Bca sem 5 c# practical

 

 Page. 31                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Delegate Example 2: Code: delegate int arithm(int x, int y); public partial class practical_82 : System.Web.UI.Page { static int addition(int x, int y) { return x + y; } static int subtraction(int x, int y) { return x - y; } static int multiplication(int x, int y) { return x * y; } static int division(int x, int y) { return x / y; } static int dooperation(int x, int y, arithm delobj) { int result = delobj(x, y); return result; } protected void Page_Load(object sender, EventArgs e) { int a=25, b=2; Response.Write("Value of A is: " + a + " , Value of B is: " + b + "<br>"); Response.Write("Addition:" + dooperation(a, b, addition) + "<br>"); Response.Write("Subtraction:" + dooperation(a, b, subtraction) + "<br>"); Response.Write("Multiplication:" + dooperation(a,b,multiplication) + "<br>"); Response.Write("Division:" + dooperation(a, b, division) + "<br>"); } }

Output:

Page 32: Bca sem 5 c# practical

 

 Page. 32                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Delegate Example 3: Code: public delegate double Delegate_eval(int a, int b); public partial class practical_8 : System.Web.UI.Page { int v1 = 25; int v2 = 2; double result = 0; static double fn_addvalues(int val1, int val2) { return val1 + val2; } static double fn_subvalues(int val1, int val2) { return val1 - val2; } static double fn_mulvalues(int val1, int val2) { return val1 * val2; } static double fn_divvalues(int val1, int val2) { return val1 / val2; } protected void Page_Load(object sender, EventArgs e) {

Response.Write("Value of V1:" + v1 + ", Value of V2:" + v2 + "<br>"); Delegate_eval deladdObj = new Delegate_eval(fn_addvalues); result = deladdObj(v1, v2); Response.Write("Addition:" + result + "<br>"); Delegate_eval delsubObj = new Delegate_eval(fn_subvalues); result = delsubObj(v1, v2); Response.Write("Subtraction: " + result + "<br>"); Delegate_eval delmulObj = new Delegate_eval(fn_mulvalues); result = delmulObj(v1, v2); Response.Write("Multiplication: " + result + "<br>"); Delegate_eval deldivObj = new Delegate_eval(fn_divvalues); result = deldivObj(v1, v2); Response.Write("Division:" + result + "<br>"); } }

Page 33: Bca sem 5 c# practical

 

 Page. 33                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Output:

  

Practical: 9 - Write an Asp.Net program using while or for loop to print sum of first 100 ODD and Even Numbers.  

Code: public partial class practical_9 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {

int no, oddsum=0, evensum=0; for (no = 1; no <= 100; no++) { if (no % 2 == 0) { evensum += no; // evensum = evensum + no; Response.Write("<b>" + no + " is Even Number, Sum: " +

evensum + "</b><br/>"); } else { oddsum += no; // oddsum = oddsum + no; Response.Write("<i>" + no + " is Odd Number, Sum: " +

oddsum + "</i><br/>"); } } Response.Write("-------------------------Total is-------------<br />"); Response.Write("<b>Sum of First 100 Odd Number is : </b>" +

oddsum.ToString() + "<br />");

Page 34: Bca sem 5 c# practical

 

 Page. 34                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Response.Write("<b>Sum of First 100 Even Number is : </b>" + evensum.ToString() + "<br />");

} }

Output:

   

Page 35: Bca sem 5 c# practical

 

 Page. 35                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 10 - Write an Asp.Net Program to add the value of Text Box in to Dropdown List and List box Controls. Practical_10.aspx : Code <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>add the value of Text Box in to Dropdown List and List box Controls.</title> </head> <body> <form id="form1" runat="server"> <div style="width: 466px" > <asp:Label ID="Label1" runat="server" Text="Enter Value : "></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Width="224px"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add to Drop Down" Width="142px" />

<asp:Button ID="Button2" runat="server" Text="Add to list Box" OnClick="Button2_Click" Width="146px" /><br />

<asp:DropDownList ID="DropDownList1" runat="server" Height="19px" Width="139px"> </asp:DropDownList> <asp:ListBox ID="ListBox1" runat="server" Height="105px" Width="143px" style="margin-left: 10px"></asp:ListBox><br />

<b>Add the value of Text Box in to Dropdown List and List box Controls. </b> </div>

</form> </body> </html> Practical_10.aspx.cs : Code public partial class practical_10 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { DropDownList1.Items.Add(TextBox1.Text); } protected void Button2_Click(object sender, EventArgs e) { ListBox1.Items.Add(TextBox1.Text); } } Output:

Page 36: Bca sem 5 c# practical

 

 Page. 36                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 11 - Write an Asp.Net Program to Delete Items from Dropdown list and List box. Practical_11.aspx: code <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Practical-11 Add to List box and dropdonbox</title> </head> <body> <form id="form1" runat="server"> <div> <br /> <asp:Label ID="Label1" runat="server" Text="Enter Value : "></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Width="219px"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add to Drop Down" Width="144px" /> &nbsp;<asp:DropDownList ID="DropDownList1" runat="server" Height="22px" Width="156px"> </asp:DropDownList> <asp:Button ID="Button3" runat="server" Text="Click to Remove from Drop Down" Width="265px" OnClick="Button3_Click" /> <br /> <asp:Button ID="Button2" runat="server" Text="Add to list Box" OnClick="Button2_Click" Width="146px" /> <asp:ListBox ID="ListBox1" runat="server" Height="105px" Width="161px"></asp:ListBox> <asp:Button ID="Button4" runat="server" Text="Click to Remove from List Box" OnClick="Button4_Click" /> </div> </form> </body> </html> Practical_11.aspx.cs: code public partial class practical_11 : System.Web.UI.Page { // Practical-11 : Write an Asp.Net Program to Delete Items from Dropdown list and List box. protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { DropDownList1.Items.Add(TextBox1.Text); } protected void Button2_Click(object sender, EventArgs e)

Page 37: Bca sem 5 c# practical

 

 Page. 37                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

{ ListBox1.Items.Add(TextBox1.Text); } protected void Button3_Click(object sender, EventArgs e) { DropDownList1.Items.Remove(DropDownList1.SelectedItem); } protected void Button4_Click(object sender, EventArgs e) { ListBox1.Items.Remove(ListBox1.SelectedItem); } }

Output:  

Page 38: Bca sem 5 c# practical

 

 Page. 38                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 12 - Write an Asp.Net Program to set Image on Image Control according to selection of image name from dropdown list. Practical_12.aspx: Code <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Image and Dropdown List</title> </head> <body> <form id="form1" runat="server"> <div> <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" onselectedindexchanged="ListBox1_SelectedIndexChanged"></asp:ListBox> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> </asp:DropDownList> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <asp:Image ID="Image1" runat="server" Height="309px" /> </div> </form> </body> </html> Practical_12.aspx.cs using System.IO; public partial class practical_12 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) //if (this.IsPostBack==false) { ListBox1.Items.Add("1.jpg"); ListBox1.Items.Add("2.jpg"); ListBox1.Items.Add("3.jpg"); ListBox1.Items.Add("4.jpg"); ListBox1.Items.Add("5.jpg"); // read all files from Images subfolder DirectoryInfo diFiles = new DirectoryInfo(Server.MapPath("~/Images/")); // Get all .jpg files DropDownList1.DataSource = diFiles.GetFiles("*.jpg"); // and bind data to list box DropDownList1.DataBind(); } } protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) {

Page 39: Bca sem 5 c# practical

 

 Page. 39                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Image1.ImageUrl=ListBox1.SelectedItem.ToString(); Label1.Text = ListBox1.SelectedItem.ToString(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownList1.SelectedIndex > 0) { Image1.ImageUrl = "Images/" + DropDownList1.SelectedItem.Value; Label1.Text = DropDownList1.SelectedItem.ToString(); } } } Output:

Page 40: Bca sem 5 c# practical

 

 Page. 40                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 13 - Write an Asp.Net Program to demonstrate use of Master Page using Themes. How to Create Theme: Step 1: Right Click on your web site.

  Step 2: Select Add ASP.NET Folder. Step 3: Click on Theme. Now App_Theme Folder is Created. The Theme Folder is created automatically under the App_Theme just Rename and give the name of theme which you want. If you want to create more theme Folder, follow step 1 to step 3 again.

Page 41: Bca sem 5 c# practical

 

 Page. 41                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step 4: Now, Right Click on App_Theme Folder and select Add New Item.

Here you can see Add New Item Window. Select Style Sheet, give the name and click on add button. Your css file is created. Step: 5 Double click on css file and write the code below: Code: Mycss.css Body {

background-color: Orange; } h1 {

font-size: 25px; color: Blue;

} p { background-color: Blue; font-family: Arial, "Comic Sans MS", "Courier New", Verdana; font-size: 20px; }

Page 42: Bca sem 5 c# practical

 

 Page. 42                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step: 6 now, add a skin file for giving style to the server controls. Right Click on App_Theme Folder and select Add New Item.

Here you can see Add New Item Window. Select Skin File, give the name and click on add button. Your skin file is created. Step: 8 now, Double click on skin file and write the code below: Code: myskin.skin <asp:TextBox runat="server" ForeColor="blue" Font-Size="30px" /> <asp:DropDownList runat="server" BackColor="blue" Width=”200px” /> <asp:Label runat="server" ForeColor="yellow" BackColor="blue" Font-Size="50px" /> Step: 9 open Source view of your .aspx file and write the code below or put textbox, dropdownlist and label control in the web form. Code: MasterPage.master <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <asp:ContentPlaceHolder id="head" runat="server">

Page 43: Bca sem 5 c# practical

 

 Page. 43                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

</asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <h1>Master Page with Theme</h1> <asp:Label ID="Label1" runat="server" Text="Label Control in Master Page..."> </asp:Label> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> <p>Demostration of Master page with Theme.</p> </div> </form> </body> </html> Code: Practical-131.aspx <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="practical-131.aspx.cs" Inherits="practical_131" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div> <h1>Theme Example</h1> <br /> <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <br /> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> </asp:DropDownList> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </div> </asp:Content> Step: 10 Now, Open Web.config file and replace <pages> with <pages theme="blue"> If you have created more than one theme, then just replace the theme name in web config. Ex. <pages theme=”blue”> or <pages theme=”moderntheme”> etc… Open your web site, the theme will interact with you web page and it’s server Controls.

Page 44: Bca sem 5 c# practical

 

 Page. 44                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Output

   

Page 45: Bca sem 5 c# practical

 

 Page. 45                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical 14 : 15 : 16 : 17 : 18 -> practical-14.aspx

Write an Asp.Net Program to perform Insert and update operation in Database. Write an Asp.Net program to perform Search and Delete operation in Database. Write an Asp.net program to display the records from database using Data Reader Object. Write an Asp.Net Program to demonstrate the various methods of Dataset Object. Write an Asp.Net Program to demonstrate Login Page using Database. How to create and Attach Database in our website. First of all add App_Data Folder in our website. Here we will use database file and attach the database to our web site. Step: 1 In Solution Explorer: Right Click on Our website root -> goto Add ASP.NET Folder -> and click on App_Data.

  

Step: 2 In Solution Explorer Right Click on App_Data -> click on Add New Item  

  

Page 46: Bca sem 5 c# practical

 

 Page. 46                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step: 3 Select SQL Server Database, Write the name of Database and Click on Add Button.  

  

We have successfully added new database to our website. Let’s check and open it to create table. Step: 4 Now Open Server Explorer and double click on our database.

  

Now we have opened database and connected to the database ‘emp’ . let’s create table in our database.

Page 47: Bca sem 5 c# practical

 

 Page. 47                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Step:5 Right Click on Tables under our Database ‘emp’ and then click on “Add New Table”  

  

Now Create Fields for our table.  

  

Now save your table. Give the name of table “tabemp” and click on ‘OK’ Button. ‘tabemp’ table is created. You can See table “tabemp” and it’s fields.  

Page 48: Bca sem 5 c# practical

 

 Page. 48                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Design Your Web Page for Database Manipulation (Insert, Update, Delete etc….) Code: Practical14.aspx  

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .style1 { width: 300px; } </style> </head> <body> <form id="form1" runat="server"> <table cellpadding="2" class="style1"> <tr> <td colspan="2" style="text-align: center"> <h1>Fill Employee Details</h1></td> </tr> <tr> <td colspan="2"> <hr /></td> </tr> <tr> <td style="text-align: left" colspan="2"> <asp:Label ID="lblwelcome" runat="server" Text="Label"></asp:Label> &nbsp;<asp:Button ID="btnlogout" runat="server" onclick="btnlogout_Click" Text="Logout" /> <asp:Button ID="btnlogin" runat="server" onclick="btnlogin_Click" Text="Login" /> </td> </tr> <tr> <td style="text-align: right"> <asp:Button ID="btnsearch" runat="server" onclick="btnsearch_Click" Text="Search" /> </td> <td> <asp:TextBox ID="txtsearch" runat="server"></asp:TextBox> </td> </tr> <tr> <td> Employee ID</td> <td> <asp:TextBox ID="txtid" runat="server"></asp:TextBox> </td>

Page 49: Bca sem 5 c# practical

 

 Page. 49                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

</tr> <tr> <td> Employee Name</td> <td> <asp:TextBox ID="txtname" runat="server"></asp:TextBox> </td> </tr> <tr> <td> Employee City</td> <td> <asp:TextBox ID="txtcity" runat="server"></asp:TextBox> </td> </tr> <tr> <td colspan="2"> <asp:Button ID="btnadd" runat="server" Text="Add" Width="64px" onclick="btnadd_Click" /> &nbsp;<asp:Button ID="btnupdate" runat="server" Text="Update" Width="60px" onclick="btnupdate_Click" /> &nbsp;<asp:Button ID="btmdelete" runat="server" onclick="btmdelete_Click" Text="Delete" /> &nbsp;<asp:Button ID="btnclear" runat="server" onclick="btnclear_Click" Text="Clear" /> </td> </tr> <tr> <td colspan="2"> <asp:GridView ID="empgrid" runat="server"> </asp:GridView> </td> </tr> </table> <p> <asp:Label ID="lblmsg" runat="server"></asp:Label> </p> </form> </body> </html>

Page 50: Bca sem 5 c# practical

 

 Page. 50                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

 

 

Page 51: Bca sem 5 c# practical

 

 Page. 51                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical-14.aspx.cs 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; protected void Page_Load(object sender, EventArgs e) { if (Session["userid"] != null) { btnlogout.Visible = true; lblwelcome.Text = Session["username"].ToString(); btnlogin.Visible = false; } else { btnlogout.Visible = false; lblwelcome.Text = "Guest"; btnlogin.Visible = true; } string tbquery = "select * from tabemp"; SqlConnection dbcon = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\emp.mdf;Integrated Security=True;User Instance=True;Trusted_Connection=yes"); SqlDataAdapter da = new SqlDataAdapter(tbquery, dbcon); DataSet ds = new DataSet(); da.Fill(ds, "tabemp"); empgrid.DataSource = ds; empgrid.DataBind(); /* SqlCommand cmd = new SqlCommand(tbquery, dbcon); SqlDataReader datareader; try { dbcon.Open(); datareader = cmd.ExecuteReader(); datareader.Read(); txtid.Text = datareader["empid"].ToString(); txtname.Text = datareader["empname"].ToString(); txtcity.Text = datareader["city"].ToString(); datareader.Close();

Page 52: Bca sem 5 c# practical

 

 Page. 52                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

} catch (Exception err) { lblmsg.Text = err.Message; } finally { dbcon.Close(); }*/ } protected void btnadd_Click(object sender, EventArgs e) { string tbquery = "insert into tabemp(empid,empname,city) values('" + txtid.Text + "','" + txtname.Text + "','" + txtcity.Text + "')"; SqlConnection dbcon = new SqlConnection(); dbcon.ConnectionString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\emp.mdf;Integrated Security=True;User Instance=True;Trusted_Connection=yes"; SqlCommand cmd = new SqlCommand(tbquery, dbcon); int newrec; try { dbcon.Open(); newrec = cmd.ExecuteNonQuery(); lblmsg.Text = newrec.ToString() + "Record Inserted..."; } catch (Exception err) { lblmsg.Text = err.Message; } finally { if (dbcon != null) { dbcon.Close(); } } } protected void btnsearch_Click(object sender, EventArgs e) { if(txtsearch.Text=="") { Response.Write("<script>alert('Please enter empid');</script>"); } string tbquery = "select * from tabemp where empid='"+txtsearch.Text+"'"; SqlConnection dbcon = new SqlConnection();

Page 53: Bca sem 5 c# practical

 

 Page. 53                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

dbcon.ConnectionString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\emp.mdf;Integrated Security=True;User Instance=True;Trusted_Connection=yes"; SqlCommand cmd = new SqlCommand(tbquery, dbcon); SqlDataReader datareader; { dbcon.Open(); datareader = cmd.ExecuteReader(); if (!datareader.Read()) { Response.Write("<script>alert('No Data....');</script>"); } else { txtid.Text = Convert.ToString(datareader["empid"]); txtname.Text = Convert.ToString(datareader["empname"]); txtcity.Text = Convert.ToString(datareader["city"]); } datareader.Close(); dbcon.Close(); } } protected void btnupdate_Click(object sender, EventArgs e) { string tbquery = "update tabemp set empid='" + Convert.ToInt32(txtid.Text) + "',empname='" + txtname.Text + "',city='" + txtcity.Text + "'where empid='" + Convert.ToInt32(txtsearch.Text) + "'"; SqlConnection dbcon = new SqlConnection(); dbcon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\emp.mdf;Integrated Security=True;User Instance=True;Trusted_Connection=yes"; SqlCommand cmd = new SqlCommand(tbquery, dbcon); try { dbcon.Open(); cmd.ExecuteNonQuery(); lblmsg.Text = "Record Updated..."; } catch (Exception err) { lblmsg.Text = err.Message; } finally { if (dbcon != null) { dbcon.Close(); }

Page 54: Bca sem 5 c# practical

 

 Page. 54                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

} } protected void btnclear_Click(object sender, EventArgs e) { txtid.Text = ""; txtname.Text = ""; txtcity.Text = ""; } protected void btmdelete_Click(object sender, EventArgs e) { string tbquery = "delete from tabemp where empid='" + Convert.ToInt32(txtid.Text) + "'"; SqlConnection dbcon = new SqlConnection(); dbcon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\emp.mdf;Integrated Security=True;User Instance=True;Trusted_Connection=yes"; SqlCommand cmd = new SqlCommand(tbquery, dbcon); try { dbcon.Open(); cmd.ExecuteNonQuery(); lblmsg.Text = "Record Deleted..."; } catch (Exception err) { lblmsg.Text = err.Message; } finally { if (dbcon != null) { dbcon.Close(); } } } protected void btnlogout_Click(object sender, EventArgs e) { Session["userid"] = null; Session["username"] = null; Response.Redirect("~/practical-18.aspx"); } protected void btnlogin_Click(object sender, EventArgs e) { Server.Transfer("~/practical-18.aspx"); } }

Page 55: Bca sem 5 c# practical

 

 Page. 55                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Output: Insert Record:

   

 

Page 56: Bca sem 5 c# practical

 

 Page. 56                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Update Record:  

   

 

Page 57: Bca sem 5 c# practical

 

 Page. 57                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Search Record: 

  

Page 58: Bca sem 5 c# practical

 

 Page. 58                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Delete Record: 

  

 

Page 59: Bca sem 5 c# practical

 

 Page. 59                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Practical: 18 - Write an Asp.Net Program to demonstrate Login Page using Database. Code : Practical-18.aspx <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .style1 { width: 300px; } </style> </head> <body> <form id="form1" runat="server"> <table class="style1"> <tr> <td colspan="2"> If you are not register.... please register first. otherwise you can login</td> </tr> <tr> <td colspan="2"> Register.....</td> </tr> <tr> <td style="text-align: right"> Username</td> <td> <asp:TextBox ID="txtreguser" runat="server"></asp:TextBox> </td> </tr> <tr> <td style="text-align: right"> Password</td> <td> <asp:TextBox ID="txtregpass" runat="server" TextMode="Password"></asp:TextBox> </td> </tr> <tr> <td> &nbsp;</td> <td> <asp:Button ID="btnreg" runat="server" Text="Register" onclick="btnreg_Click" /> </td> </tr> <tr>

Page 60: Bca sem 5 c# practical

 

 Page. 60                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

<td colspan="2"> <asp:Label ID="lblmsg" runat="server"></asp:Label> </td> </tr> <tr> <td colspan="2"> <hr />Login......</td> </tr> <tr> <td style="text-align: right"> User</td> <td> <asp:TextBox ID="txtuser" runat="server"></asp:TextBox> </td> </tr> <tr> <td style="text-align: right"> Password</td> <td> <asp:TextBox ID="txtpass" runat="server" TextMode="Password"></asp:TextBox> </td> </tr> <tr> <td> &nbsp;</td> <td> <asp:Button ID="btnlogin" runat="server" Text="Login" onclick="btnlogin_Click" /> </td> </tr> </table> </form> </body> </html>

Page 61: Bca sem 5 c# practical

 

 Page. 61                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Output:

Page 62: Bca sem 5 c# practical

 

 Page. 62                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Code : Practical-18.aspx.cs 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; public partial class practical_18 : System.Web.UI.Page { // Practical-18 : Write an Asp.Net Program to demonstrate Login Page using Database. protected void Page_Load(object sender, EventArgs e) { } protected void btnreg_Click(object sender, EventArgs e) { string tbquery = "insert into login(username,password) values('" + txtreguser.Text + "','" + txtregpass.Text + "')"; SqlConnection dbcon = new SqlConnection(); dbcon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\emp.mdf;Integrated Security=True;User Instance=True;Trusted_Connection=yes"; SqlCommand cmd = new SqlCommand(tbquery, dbcon); int newrec; try { dbcon.Open(); newrec = cmd.ExecuteNonQuery(); lblmsg.Text = newrec.ToString() + "Registration Successfully Completed..."; } catch (Exception err) { lblmsg.Text = err.Message; } finally { if (dbcon != null) { dbcon.Close(); } } } protected void btnlogin_Click(object sender, EventArgs e) {

Page 63: Bca sem 5 c# practical

 

 Page. 63                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

string tbquery = "select * from login where username='" + txtuser.Text + "' and password='" + txtpass.Text + "'"; SqlConnection dbcon = new SqlConnection(); dbcon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\emp.mdf;Integrated Security=True;User Instance=True;Trusted_Connection=yes"; SqlCommand cmd = new SqlCommand(tbquery, dbcon); SqlDataReader datareader; { dbcon.Open(); datareader = cmd.ExecuteReader(); if (!datareader.Read()) { Response.Write("<script>alert('You are not registered user....');</script>"); } else { Session["userid"] = Convert.ToString(datareader["userid"]); Session["username"] = Convert.ToString(datareader["username"]); Response.Redirect("~/practical-14.aspx"); } datareader.Close(); dbcon.Close(); } } }

Page 64: Bca sem 5 c# practical

 

 Page. 64                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

OutPut: Register for Login:

 

Page 65: Bca sem 5 c# practical

 

 Page. 65                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA) 

Login to Employee Form: practical14.aspx  

  After Successful Login:  

Page 66: Bca sem 5 c# practical

 

 Page. 66                                                                  Prepared By: Hitesh Patel (Asst. Professor, GrowMore BCA/PGDCA)