SlideShare ist ein Scribd-Unternehmen logo
1 von 61
090360116058                                                             Dot Net Technology


                                 PRACTICAL NO: 1

AIM: Write a program for Arithmetic Calculator using Console &
Windows Application in C# & VB.NET.


                                 Console Calculator.cs



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

namespace CSConsoleApplicationCalculator
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, n;

            Console.WriteLine("Calculator in C# Console Application ");
            Console.WriteLine("enter the value of A");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("enter the value of B");
            b = int.Parse(Console.ReadLine());
            Console.WriteLine("enter choice n 1 = Addition n 2 = Substraction n 3 =
Multiplication n 4 = Division");
            n = int.Parse(Console.ReadLine());

              Program p = new Program();
              if (n == 1)
              {
                   p.add(a, b);
              }
              else if (n == 2)
              {
                   p.sub(a, b);
              }
              else if (n == 3)
              {
                   p.mul(a, b);
              }
              else if (n == 4)
              {
                   p.div(a, b);
              }
              else
              {
                   Console.WriteLine("YOU ARE ENTERING WRONG CHOICE");
              }

              Console.ReadKey();
          }
          public void add(int a, int b)


Om Shanti Engg. College - 2012                                                           1
090360116058                                               Dot Net Technology


        {
             int c;
             c = a + b;
             Console.WriteLine("Addition is " + c);
        }
        public void sub(int a, int b)
        {
            int c;
            c = a - b;
            Console.WriteLine("Substraction is " + c);
        }
        public void mul(int a, int b)
        {
            int c;
            c = a * b;
            Console.WriteLine("Multiplication is " + c);
        }
        public void div(int a, int b)
        {
            int c;
            c = a / b;
            Console.WriteLine("Division is " + c);
        }
    }
}




Om Shanti Engg. College - 2012                                             2
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                   3
090360116058                                             Dot Net Technology


                                 Console Calculator.vb



Module Module1

    Sub Main()
        Dim a, b, c As Integer


        Console.WriteLine("Enter Value of a")
        a = Convert.ToInt16(Console.ReadLine())
        Console.WriteLine("Enter Value of a")
        b = Convert.ToInt16(Console.ReadLine())

        c = a + b
        Console.WriteLine("Addition")
        Console.WriteLine(+c)
        c = a - b
        Console.WriteLine("Substraction")
        Console.WriteLine(+c)
        c = a * b
        Console.WriteLine("Multiplication")
        Console.WriteLine(+c)
        c = a / b
        Console.WriteLine("Division")
        Console.WriteLine(+c)

        Console.ReadKey()
    End Sub

End Module




Om Shanti Engg. College - 2012                                           4
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                   5
090360116058                                                Dot Net Technology


                                 Windows Calculator.cs



using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Linq;
using   System.Text;
using   System.Windows.Forms;

namespace VBWindowsFormsApplicationCalculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            txtAns.Text = (Convert.ToInt32(txtA.Text) +
Convert.ToInt32(txtB.Text)).ToString();
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            txtAns.Text = (Convert.ToInt32(txtA.Text) -
Convert.ToInt32(txtB.Text)).ToString();
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            txtAns.Text = (Convert.ToInt32(txtA.Text) *
Convert.ToInt32(txtB.Text)).ToString();
        }

        private void Button4_Click(object sender, EventArgs e)
        {
            txtAns.Text = (Convert.ToInt32(txtA.Text) /
Convert.ToInt32(txtB.Text)).ToString();
        }
    }
}




Om Shanti Engg. College - 2012                                              6
090360116058                     Dot Net Technology



OUTPUT :




Om Shanti Engg. College - 2012                   7
090360116058                                                         Dot Net Technology




                                 Windows Calculator.vb



Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

        TextBox3.Text = Convert.ToInt32(TextBox1.Text) +
Convert.ToInt32(TextBox2.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

        TextBox3.Text = Convert.ToInt32(TextBox1.Text) -
Convert.ToInt32(TextBox2.Text)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

        TextBox3.Text = Convert.ToInt32(TextBox1.Text) *
Convert.ToInt32(TextBox2.Text)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click

        TextBox3.Text = Convert.ToInt32(TextBox1.Text) /
Convert.ToInt32(TextBox2.Text)
    End Sub
End Class




Om Shanti Engg. College - 2012                                                       8
090360116058                     Dot Net Technology



OUTPUT :




Om Shanti Engg. College - 2012                   9
090360116058                                                            Dot Net Technology


                                 PRACTICAL NO: 2

AIM: Implement a C# Application to Study Inheritance , Constructor and
Overloading.
                                      Inheritance.cs



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

namespace CSConsoleInheritance
{
    class Program
    {
        static void Main(string[] args)
        {

              Console.WriteLine("Inheritance Programn");
              Console.WriteLine("Creating Object of Derive classn");
              Derive d=new Derive();
              Console.WriteLine("Calling Base class method");
              d.Display();
              Console.WriteLine("Calling Derive class method");
              d.Print();
              Console.ReadKey();
        }
    }
    class BaseClass
    {
        public void Display()
        {
            Console.WriteLine("This is Base class Display() methodn");
        }
    }
    class Derive :BaseClass
    {
        public void Print()
        {
            Console.WriteLine("This is derive class Print() method");
        }
    }
}




Om Shanti Engg. College - 2012                                                         10
090360116058                     Dot Net Technology




OUTPUT :




Om Shanti Engg. College - 2012                  11
090360116058                                                           Dot Net Technology




                                 ConstuctorOverloding.cs



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

namespace CSConsoleConstructorOverLoading
{
    class Program
    {
        public Program()
        {
            Console.WriteLine("This is Default Constructorn");
        }
        public Program(String nm)
        {
            Console.WriteLine("This is one Parameter Constructor");
            Console.WriteLine("My Name is : " + nm + "n");
        }
        public Program(int a, string nm)
        {
            Console.WriteLine("This is two Parameter Constructor");
            Console.WriteLine("My Name is : " + nm + " and i am : " + a + " years old
");
        }
        ~Program()
        {
            Console.WriteLine("I am calling Destructor");
        }
        public static void Main(string[] args)
        {

              Console.WriteLine("This is Costructor and Destructor in C#n");
              Program prg = new Program();
              Program prg1 = new Program("abc");
              Program prg2 = new Program(20, "abc");


              Console.ReadKey();
          }
    }
}




Om Shanti Engg. College - 2012                                                        12
090360116058                     Dot Net Technology




OUTPUT :




Om Shanti Engg. College - 2012                  13
090360116058                                                             Dot Net Technology



                                 PRACTICAL NO: 3

AIM:Write a Programm to Demostrate the use of property and indexer.
                                 Read & Write Property.cs


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

namespace CSConsoleProperty
{
    class Program
    {
        private string BookName = "abc";
        private int BookPrice = 500;
        public string MyBookName
        {
            get
            {
                return BookName;
            }
            set
            {
                BookName = value;
            }
        }
        public int MyBookPrice
        {
            get
            {
                return BookPrice;
            }
            set
            {
                BookPrice = value;
            }
        }
        public override string ToString()
        {
            return ("BookName is : " + BookName + " Price is : " + BookPrice);
        }
        static void Main(string[] args)
        {
            Program p = new Program();

                Console.WriteLine("This is Read & Write Property Programn");
                Console.WriteLine("Default values is :");
                Console.WriteLine(p+"n");
                p.BookName = ".net Black Book";
                p.BookPrice = 450;
                Console.WriteLine("Changed Value is :");
                Console.WriteLine(p);
                Console.ReadKey(); }
            }
        }


Om Shanti Engg. College - 2012                                                          14
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  15
090360116058                                                         Dot Net Technology


                                 Read Only Property.cs



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

namespace CSConsoleProperty2
{
    class ReadOnly
    {
        private string BookName = "abc";
        private int BookPrice = 500;
        public ReadOnly()
        { }
        public ReadOnly(String Name,int Price)
        {
            BookName = Name;
            BookPrice = Price;
        }
        public string MyBookName
        {
            get
            {
                return BookName;
            }
        }
        public int MyBookPrice
        {
            get
            {
                return BookPrice;
            }
        }
        public override string ToString()
        {
            return ("BookName is : " + BookName + " and Price is : " + BookPrice);
        }
        static void Main(string[] args)
        {

              ReadOnly p = new ReadOnly();
              Console.WriteLine("This is Read only Propertyn");
              Console.WriteLine("Default values is :");
              Console.WriteLine(p + "n");
              ReadOnly p1 = new ReadOnly(".net Black Book", 450);
              Console.WriteLine("Changed Value is :");
              Console.WriteLine(p1);
              Console.ReadKey();
          }
    }
}




Om Shanti Engg. College - 2012                                                       16
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  17
090360116058                                                           Dot Net Technology


                                 Static Property.cs



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

namespace CSConsoleProperty3
{
    class Static
    {
        static void Main(string[] args)
        {

              Console.WriteLine("Static Property Programn");
              Console.WriteLine("Number of Object : {0}",CounterClass.NumberOfObject);
              CounterClass Object1 = new CounterClass();
              Console.WriteLine("Number of Object : {0}", CounterClass.NumberOfObject);
              CounterClass Object2 = new CounterClass();
              Console.WriteLine("Number of Object : {0}", CounterClass.NumberOfObject);
              CounterClass Object3 = new CounterClass();
              Console.WriteLine("Number of Object : {0}", CounterClass.NumberOfObject);
              Console.ReadKey();
        }
    }
    public class CounterClass
    {
        private static int n = 0;
        public CounterClass()
        {
            n++;
        }
        public static int NumberOfObject
        {
            get
            {
                 return n;
            }
            set
            {
                 n = value;
            }
        }
    }
}




Om Shanti Engg. College - 2012                                                        18
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  19
090360116058                                                    Dot Net Technology


                                      Indexer.cs



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

namespace indexer
{
    class indexers
    {
        int[] a = new int[3];
        public int this[int index]
        {
            get
            {
                if (index < 0 && index > 3)
                {
                    return 0;
                }
                else
                {
                    return a[index];
                }
            }
            set
            {
                a[index] = value;
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {

              Console.WriteLine("This is indexer Programn");
              indexers i = new indexers();
              i[0] = 100;
              i[1] = 200;
              i[2] = 300;

              for (int j = 0; j <= 2; j++)
              {
                  Console.WriteLine("Value is : " + i[j]);
              }

              Console.WriteLine("Changing values");

              i[0] = 101;
              i[1] = 202;
              i[2] = 303;

              for (int j = 0; j <= 2; j++)
              {
                  Console.WriteLine("Value is : " + i[j]);
              }
              Console.ReadKey();
          } } }

Om Shanti Engg. College - 2012                                                 20
090360116058                     Dot Net Technology


    OUTPUT :




Om Shanti Engg. College - 2012                  21
090360116058                                                 Dot Net Technology


                                 PRACTICAL NO: 4

AIM: Write a Program for explaining events and Delegates in C# .NET.




                                      Events.cs



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

namespace events
{
    public delegate void eventhandler();
    class Program
    {
        public static event eventhandler show;
        static void Main(string[] args)
        {
            Console.WriteLine("This is events Programn");
            show += new eventhandler(Dog);
            show += new eventhandler(Cat);
            show += new eventhandler(Mouse);
            show += new eventhandler(Mouse);
            show.Invoke();
            Console.ReadKey();
        }
        static void Dog()
        {
            Console.WriteLine("Dog");
        }
        static void Cat()
        {
            Console.WriteLine("Cat");
        }
        static void Mouse()
        {
            Console.WriteLine("Mouse");
        }

    }
}




Om Shanti Engg. College - 2012                                              22
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  23
090360116058                                                      Dot Net Technology


                                      Delegates.cs



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

namespace delegates
{
    class Program
    {
        public delegate int calci(int i,    int j);
        public static int add(int a, int    b)
        {
            return a + b;
        }
        public static int sub(int a, int    b)
        {
            return a - b;
        }
        public static int mul(int a, int    b)
        {
            return a * b;
        }
        public static int div(int a, int    b)
        {
            return a / b;
        }
        static void Main(string[] args)
        {

              Console.WriteLine("This is delegates Programn");
              calci c;
              c = add;
              Console.WriteLine("add {0}", c.Invoke(50, 20));
              c = sub;
              Console.WriteLine("sub {0}", c.Invoke(100, 20));
              c = mul;
              Console.WriteLine("mul {0}", c.Invoke(50, 25));
              c = div;
              Console.WriteLine("div {0}", c.Invoke(30, 30));
              Console.ReadKey();
          }
    }
}




Om Shanti Engg. College - 2012                                                   24
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  25
090360116058                                                               Dot Net Technology


                                 PRACTICAL NO: 5


AIM: Implement Windows Form based application using controls like
menus, dialog and tool tip etc.


Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
        End Sub
        Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles FileToolStripMenuItem.Click
        End Sub
        Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ToolStripItemClickedEventArgs)
        End Sub
        Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles EditToolStripMenuItem.Click
        End Sub
        Private Sub ProjectToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ProjectToolStripMenuItem.Click
        End Sub
        Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles HelpToolStripMenuItem.Click
        End Sub
        Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NewToolStripMenuItem.Click
        End Sub
End Class




Om Shanti Engg. College - 2012                                                             26
090360116058                     Dot Net Technology




OUTPUT :




.




Om Shanti Engg. College - 2012                  27
090360116058                                                  Dot Net Technology




                                 PRACTICAL NO: 6

AIM: Implement a VB 2008 Application to study Error Handling.




                                 Error Handling.cs



Module Module1

     Sub Main()

          Dim a As Integer
          Dim b As Integer = 1
          Dim c As Integer = 0

          Try
             a = b  c
         Catch exc As Exception
             Console.WriteLine("A run-time error occurred")
         Finally
             Console.ReadLine()
         End Try
     End Sub

End Module




Om Shanti Engg. College - 2012                                               28
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  29
090360116058                                                             Dot Net Technology




                                 PRACTICAL NO: 7


AIM: Implement concepts of Inheritance, visual inheritance and Interface
in windows application.

Public Interface person
  Sub setnum(ByVal n1 As Double, ByVal n2 As Double)
  Function getsum() As Double
End Interface
Public Class employee Implements person
  Dim s1 As Double
 Public Function getsum() As Double Implements person.getsum
     Return s1
  End Function
 Public Sub setnum(ByVal n1 As Double, ByVal n2 As Double) Implements person.setnum
     s1 = n1 + n2
  End Sub
 Public Sub substraction(ByVal n1 As Double, ByVal n2 As Double)
     Dim d3 As Double = n1 - n2
     System.console.writeline("The substraction interface is: " & d3)
  End Sub
End Class
Public Class demo Inherits employee
  Public Sub mul(ByVal n1 As Double, ByVal n2 As Double)
     Dim d3 As Double= n1 * n2
     System.Console.WriteLine("The multiplication using inheritance is : " & d3)
  End Sub
End Class
Module Module1
  Sub Main()
     Dim d As New employee()
     Dim d5 As New demo()
     Console.WriteLine("Enter a digit:")
     Dim d1 As Double = CDbl(Console.ReadLine())
     Console.WriteLine("Enter a digit:")
     Dim d2 As Double = CDbl(Console.ReadLine())
     d.setnum(d1, d2)
     System.Console.WriteLine("The sum using interface is: " & d.getsum)
     d5.substraction(d1, d2) System.console.writeline() d5.mul(d1, d2)
  End Sub
End Module




Om Shanti Engg. College - 2012                                                          30
090360116058                     Dot Net Technology




OUTPUT :




Om Shanti Engg. College - 2012                  31
090360116058                                                                 Dot Net Technology


                                 PRACTICAL NO: 8


AIM: Use Dataset, Data Reader, XML Reader & Data Sources (SQL,
Object & XML) with Any Windows or Web Application.

                                            DataSet
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
  public partial class assDataset : System.Web.UI.Page
  {
     SqlConnection         con        =     new       SqlConnection("Data     Source=HARDIK-
B652B097SQLEXPRESS;Initial Catalog=db1;Integrated Security=True");
     SqlDataAdapter adapt;
     DataSet ds = new DataSet();
     protected void Page_Load(object sender, EventArgs e)
     {
       con.Open();
       adapt = new SqlDataAdapter("select * from Employee", con);
       adapt.Fill(ds, "Employee");
       con.Close();
     }
  }
}


                                          DataReader

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
  public partial class assrreader : System.Web.UI.Page
  {
     SqlConnection          con       =     new        SqlConnection("Data    Source=HARDIK-
B652B097SQLEXPRESS;Initial Catalog=db2;Integrated Security=True");
     SqlCommand cmd;
     SqlDataReader reader;
     String str;
     protected void Page_Load(object sender, EventArgs e)
     {
        con.Open();


Om Shanti Engg. College - 2012                                                              32
090360116058                                                       Dot Net Technology


            cmd = new SqlCommand("Select * from Employee", con);
            reader = cmd.ExecuteReader();
            reader.Close();
            con.Close();
        }
    }
}

                                            XMLReader


using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
  public partial class assXMLReader : System.Web.UI.Page
  {
     DataSet ds = new DataSet();
     protected void Page_Load(object sender, EventArgs e)
     {
       ds.ReadXml(Server.MapPath("~/assXML.xml"));
     }
  }
}




Om Shanti Engg. College - 2012                                                    33
090360116058                                                               Dot Net Technology


                                 PRACTICAL NO: 9


AIM: Use Data Controls like Data List, Grid View, Detail View, Repeater
and List Bound Control
                                          .aspx file


<%@         Page     Language="C#"      AutoEventWireup="true"     CodeBehind="ass14.aspx.cs"
Inherits="WebApplication1.ass14" %>
<!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 style="font-weight: 700">
<h2>DataList Control</h2>
     <asp:DataList ID="DataList1" runat="server">
        <ItemTemplate>
           Student name:<%#Eval("Name") %><br />Roll No:<%#Eval("Roll_No") %><br />Email
ID:<%#Eval("EmailId") %>
        </ItemTemplate>
        <SeparatorTemplate>
          <hr />
        </SeparatorTemplate>
        <AlternatingItemTemplate>
           Student name:<%#Eval("Name") %><br />Roll No:<%#Eval("Roll_No") %><br />Email
ID:<%#Eval("EmailId") %>
        </AlternatingItemTemplate>
     </asp:DataList>
 <h2>GridView Control</h2>
     <asp:GridView ID="GridView1" runat="server">
     </asp:GridView>
     <br />
<h2>DetailsView Control</h2>
     <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
        AutoGenerateRows="False" DataKeyNames="EmpId" DataSourceID="SqlDataSource1" >
        <Fields>
          <asp:BoundField DataField="EmpId" HeaderText="EmpId" ReadOnly="True"
             SortExpression="EmpId" />
          <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
          <asp:BoundField DataField="Salary" HeaderText="Salary"
             SortExpression="Salary" />
        </Fields>
     </asp:DetailsView>
     <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:db2ConnectionString %>"
        SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource>


Om Shanti Engg. College - 2012                                                             34
090360116058                                                            Dot Net Technology


    <br />
<h2>Repeater Control</h2>
    <asp:Repeater ID="Repeater1" runat="server">
       <HeaderTemplate>
         <table border="1">
            <tr>
               <th>StudName</th>
               <th>RollNo</th>
               <th>EmailID</th>
            </tr>
       </HeaderTemplate>
       <ItemTemplate>
         <tr>
            <td><%#Eval("Name") %></td>
            <td><%#Eval("Roll_No") %></td>
            <td><%#Eval("EmailId") %></td>
         </tr>
       </ItemTemplate>
       <FooterTemplate>
         </table>
       </FooterTemplate>
    </asp:Repeater>
    <br />
<h2>ListView Control</h2>
    <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
       <ItemTemplate>
            Name:<%#Eval("Name") %><dd>Salary:<%#Eval("Salary") %></dd>
       </ItemTemplate>
    </asp:ListView>
  </div>
  </form>

</body>
</html>




Om Shanti Engg. College - 2012                                                         35
090360116058                                                              Dot Net Technology


                                     Code Behind File

using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
  public partial class ass14 : System.Web.UI.Page
  {
     SqlConnection         con       =     new      SqlConnection("Data    Source=HARDIK-
B652B097SQLEXPRESS;Initial Catalog=db1;Integrated Security=True");
     SqlDataAdapter adapt;
     DataSet ds = new DataSet();
     protected void Page_Load(object sender, EventArgs e)
     {
       con.Open();
       adapt = new SqlDataAdapter("Select * from Student", con);
       adapt.Fill(ds, "Student");
       DataList1.DataSource = ds;
       DataList1.DataBind();
       GridView1.DataSource = ds;
       GridView1.DataBind();
       Repeater1.DataSource = ds;
       Repeater1.DataBind();
       con.Close();
     }
  }
}




Om Shanti Engg. College - 2012                                                           36
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  37
090360116058                                                          Dot Net Technology


                                 PRACTICAL NO: 10


AIM: Implement web application using ASP.NET with web control.
                                         .aspx file

<%@ Page Language="C#" AutoEventWireup="tr
ue" CodeBehind="Pizza.aspx.cs" Inherits="WebApplication1.Pizza" %>

<!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>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; Pizza</h2><br />
     <asp:CheckBoxList ID="CheckBoxList1" runat="server" AppendDataBoundItems="True"
        AutoPostBack="True" onselectedindexchanged="CheckBoxList1_SelectedIndexChanged"
        RepeatColumns="2">
        <asp:ListItem>Italian(500)</asp:ListItem>
        <asp:ListItem>Maxican(1000)</asp:ListItem>
        <asp:ListItem>Indian(1500)</asp:ListItem>
        <asp:ListItem>Special(2500)</asp:ListItem>
     </asp:CheckBoxList>

    <h2>&nbsp;</h2>
<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; Toping</h2>
    <asp:CheckBox ID="CheckBox5" runat="server" Text="Cheez(200/piece)"
      AutoPostBack="True" />
    <asp:CheckBox ID="CheckBox6" runat="server"
      style="z-index: 1; left: 179px; top: 247px; position: absolute"
      Text="Butter(15/piece)" AutoPostBack="True" /><br />
    <asp:CheckBox ID="CheckBox7" runat="server" Text="Bans(180/piece)"
      AutoPostBack="True" />
    <asp:CheckBox ID="CheckBox8" runat="server"
      style="z-index: 1; left: 179px; top: 275px; position: absolute"
      Text="Milk(180/piece)" AutoPostBack="True" />
      <br />
    <br />
    <br />
    <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select mode of eating</h2>
    <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
      GroupName="a" Text="Eat" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
      GroupName="a" Text="Delivery(1000)" />

Om Shanti Engg. College - 2012                                                        38
090360116058                                                                Dot Net Technology


     <br />
     <br />
&nbsp;<br />
     <asp:Button ID="Button1" runat="server" Text="Calculate"
       onclick="Button1_Click" />
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
  </div>
  </form>
</body>
</html>


                                      Code Behind File
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
  public partial class Pizza : System.Web.UI.Page
  {
     int amt, toping,cnt;
     protected void Page_Load(object sender, EventArgs e)
     {       }
     protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
     {
        amt = 0;
        for (int i = 0; i < CheckBoxList1.Items.Count; i++)
        {
          if (CheckBoxList1.Items[0].Selected)
           {
               cnt += 1;
               amt += 500;
           }
          if (CheckBoxList1.Items[1].Selected)
           {
               cnt += 1;
               amt += 1000;
           }
          if (CheckBoxList1.Items[2].Selected)
           {
               cnt += 1;
               amt += 1500;
           }
          if (CheckBoxList1.Items[3].Selected)
           {
               cnt += 1;
               amt += 2500;
           }
          ViewState["cnt"] = cnt;
          ViewState["amt"] = amt;
        }
     }


Om Shanti Engg. College - 2012                                                             39
090360116058                                                       Dot Net Technology


        protected void Button1_Click(object sender, EventArgs e)
        {
          toping = 0;
          if (CheckBox5.Checked)
             toping+=(int)ViewState["cnt"]*200;
          if (CheckBox6.Checked)
             toping += (int)ViewState["cnt"] * 15;
          if (CheckBox7.Checked)
             toping += (int)ViewState["cnt"] * 180;
          if (CheckBox8.Checked)
             toping += (int)ViewState["cnt"] * 180;
          int tot = (int)ViewState["amt"] + toping;
          if (RadioButton1.Checked)
             Label1.Text = "Your total bill for pizza is" + tot;
        }
    }
}




Om Shanti Engg. College - 2012                                                    40
090360116058                     Dot Net Technology




OUTPUT :




Om Shanti Engg. College - 2012                  41
090360116058                                                               Dot Net Technology


                                 PRACTICAL NO: 11


AIM: Write a code for web application to provide input validations using
Input Valuators.
                                          .aspx file


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="assVAlidation.aspx.cs"
Inherits="WebApplication1.assVAlidation" %>
<!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">
     .style1
     {
        text-decoration: underline;
     }
  </style>
</head>
<body>
  <form id="form1" runat="server">
  <div>
     <strong><span class="style1"><h2>Simple Application Form</h2></span><br class="style1" />
     </strong>User Name:&nbsp;&nbsp;&nbsp;
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="TextBox1">Plz enter your name</asp:RequiredFieldValidator>
     <br />
     <br />
     Password:&nbsp;&nbsp;&nbsp;
     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
     <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
        ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2">Plz enter the
password</asp:RequiredFieldValidator>
     <br />
     <br />
     Retype Password:&nbsp;&nbsp;&nbsp;
     <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
     <asp:CompareValidator ID="CompareValidator1" runat="server"
        ErrorMessage="CompareValidator" ControlToCompare="TextBox2"
        ControlToValidate="TextBox3">Password does not match</asp:CompareValidator>
     <br />
     <br />
     E-Mail:&nbsp;&nbsp;&nbsp;
     <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
     <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
        ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox4"



Om Shanti Engg. College - 2012                                                             42
090360116058                                                               Dot Net Technology


        ValidationExpression="w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*">Not
valid</asp:RegularExpressionValidator>
     <br />
     <br />
     Age:&nbsp;&nbsp;&nbsp;
     <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
     <asp:RangeValidator ID="RangeValidator1" runat="server"
        ErrorMessage="RangeValidator" ControlToValidate="TextBox5"
        MaximumValue="40" MinimumValue="20" Type="Integer">The age should be between 20
to 40</asp:RangeValidator>
     <br /> <br />
     Referrer Code:&nbsp;&nbsp;&nbsp;
     <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
     <asp:CustomValidator ID="CustomValidator1" runat="server"
        ErrorMessage="CustomValidator" ControlToValidate="TextBox6">Try a string that starts
from 014</asp:CustomValidator>
     <br /> <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <asp:Button ID="Button1" runat="server" Text="Submit" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <asp:Button ID="Button2" runat="server" Text="Cancel" />
 &nbsp;</div>
   </form>
</body>
</html>




Om Shanti Engg. College - 2012                                                             43
090360116058                     Dot Net Technology




OUTPUT :




Om Shanti Engg. College - 2012                  44
090360116058                                                                   Dot Net Technology


                                 PRACTICAL NO: 12


AIM: Create a Web application that illustrates the use of themes and
master pages with Site-Map.

                                          Main.master


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main.master.cs" Inherits="Main"
%>
<!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">
  <center>
  <table cellpadding="0" cellspacing="0" style="width:1000px; border: 1px solid black;">
  <tr>
     <td colspan="3" style="height:180px; background-color:Silver; width:1000px; border:1px solid
black;" ></td>
  </tr>
  <tr>
  <td colspan="3" style="height:35px; background-color:Gray; width:1000px; border:1px solid
black;" >
     <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
        <Items>
          <asp:MenuItem Text="Home" Value="Home"></asp:MenuItem>
          <asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem>
          <asp:MenuItem Text="Contact Us" Value="Contact Us"></asp:MenuItem>
          <asp:MenuItem Text="Services" Value="Services"></asp:MenuItem>
        </Items>
     </asp:Menu>
     </td>
  </tr>
  <tr style="width:1000px;">
     <td style="width:200px; background-color:Green; height:850px;">&nbsp;</td>
     <td style="width:550px; background-color:Green; height:850px;">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
     </td>
     <td style="width:250px;background-color:Green; height:850px;">&nbsp;</td>
  </tr>
  <tr>
     <td colspan="3" style="height:20px; width:1000px;background-color:Black;"></td>
  </tr>
  </table>
  </center>
  </form>

Om Shanti Engg. College - 2012                                                                  45
090360116058                                                             Dot Net Technology


</body>
</html>
                                        .aspx file


<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true"
CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  <p> heeeloo world...!!</p>
  <p> &nbsp;</p>
  <p> &nbsp;</p>
  <p> &nbsp;</p>
  <p>&nbsp;</p>
  <p>i am back</p>
</asp:Content>




Om Shanti Engg. College - 2012                                                          46
090360116058                     Dot Net Technology




OUTPUT :




Om Shanti Engg. College - 2012                  47
090360116058                                                             Dot Net Technology


                                 PRACTICAL NO: 13


AIM: Create a Web Application in ASP.NET using various CSS.

                                       Cssdemo1(.css file)


/* header start */
.main_bg
{
        width:100%;
        background:url(../images/homebg_header.gif) repeat-x left top;
        margin:0 auto;
}
.header_image
{
width:1003px;
height:1153px;
background-color:Teal;
margin:0 auto;
}
.bottom_image
{
width:1003px;
height:153px;
background-color:Silver;
margin:top 153px;
}

                                       Cssdemo2(.css file)
/* general top nav */
.top_links
{
        width:295px;
        float:right;
        margin:15px 0 0 0;
}
.top_links ul
{
        list-style:none;
}

.top_links ul li
{
        float:left;
        display:block;
}

.top_links ul li a
{
        text-decoration:none;


Om Shanti Engg. College - 2012                                                          48
090360116058                                                                     Dot Net Technology


         color:#4E4E4E;
         padding:0 10px 0 10px;
         font-size:12px;
}

.top_links ul li a:hover
{
        text-decoration:none;
        color:#8B8B8B;
}

.nav {
         float:right;
         width:550px;
         padding:23px 0 0 0;
         display:block;
}

                                             .aspx file


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cssdemo.aspx.cs"
Inherits="cssdemo" %>
<!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>css demo</title>
  <link href="css/cssdemo1.css" rel="stylesheet" type="text/css" />
  <link href="css/cssdemo2.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
<div class="header_image">
<div class="bottom_image">
   <div class="header">
   This is header part....
        <div class="top_links">

          <ul class="style3" dir="ltr" type="disc">
             <li>
                <div class="menu_list">
                  <ul>
                     <li>
                     <a href="#">languages<img src="images/arrow-bullet.gif" alt="global list"
width="8" height="4" /> </li>
                     </a>
                        <!--<![endif]-->
                        <!--[if lte IE 6]><table cellpadding="0" cellspacing="0"
border="0"><tr><td><![endif]-->
 <ul>
                          <li><a target="_blank"
href="http://www.freedomdesigns.in">INDIA</a></li>


Om Shanti Engg. College - 2012                                                                   49
090360116058                                                                  Dot Net Technology


                          <li><a target="_blank" href="http://www.freedomdesigns.in">UK</a></li>
                 </ul>
                 </div>
                 </li>
                 </ul>
       <br />
       </form>
</body>
</html>




Om Shanti Engg. College - 2012                                                                50
090360116058                     Dot Net Technology




OUTPUT :




Om Shanti Engg. College - 2012                  51
090360116058                                                                  Dot Net Technology




                                 PRACTICAL NO: 14


AIM: Implement the concept of state management in a web application.
                                 .asax file(Global Application file)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace WebApplication1
{
  public class Global : System.Web.HttpApplication
  {
     protected void Application_Start(object sender, EventArgs e)
     {
       Application["count"] = 0;
     }
     protected void Session_Start(object sender, EventArgs e)
     {     }
     protected void Application_BeginRequest(object sender, EventArgs e)
     {     }
     protected void Application_AuthenticateRequest(object sender, EventArgs e)
     {     }
     protected void Application_Error(object sender, EventArgs e)
     {     }
     protected void Session_End(object sender, EventArgs e)
     {     }
     protected void Application_End(object sender, EventArgs e)
     {     }
  }
}

                                             .aspx file


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
  public partial class WebForm3 : System.Web.UI.Page

Om Shanti Engg. College - 2012                                                               52
090360116058                                                              Dot Net Technology


    {
            protected void Page_Load(object sender, EventArgs e)
            {
              if (!IsPostBack)
              {
                 Application.Lock();
                 Application["count"] = (int)Application["count"] + 1;
                 Response.Write("Visitor No.=" + Application["count"]);
                 Application.UnLock();
              }
            }
            protected void Button1_Click(object sender, EventArgs e)
        {
                Session["name"] = TextBox1.Text;
                Session["pwd"] = TextBox2.Text;
                Response.Redirect("NextPage.aspx");
            }
    }
}

                                               Code Behind File


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

namespace WebApplication1
{
  public partial class WebForm3 : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
          Application.Lock();
          Application["count"] = (int)Application["count"] + 1;
          Response.Write("Visitor No.=" + Application["count"]);
          Application.UnLock();
       }
    }

            protected void Button1_Click(object sender, EventArgs e)
            {
              Session["name"] = TextBox1.Text;
              Session["pwd"] = TextBox2.Text;
              Response.Redirect("NextPage.aspx");
            }
    }
}



Om Shanti Engg. College - 2012                                                           53
090360116058                                                                Dot Net Technology


                                      NextPage.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
  public partial class NextPage : System.Web.UI.Page
  {
     protected void Page_Load(object sender, EventArgs e)
     {
       Response.Write("Welcome " + Session["name"] + ". Your password is " + Session["pwd"]);
     }
  }
}




Om Shanti Engg. College - 2012                                                                  54
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  55
090360116058                                                           Dot Net Technology


                                 PRACTICAL NO: 15

AIM: Implement code in ASP.NET that creates and consumes Web service.
                                   .asmx file(WebService)


using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
namespace WebApplication1
{
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.ComponentModel.ToolboxItem(false)]
  public class assWebServic : System.Web.Services.WebService
  {
     SqlConnection con=new SqlConnection("Data Source=HARDIK-
B652B097SQLEXPRESS;Initial Catalog=db1;Integrated Security=True");
     SqlDataAdapter adapt;
     DataSet ds=new DataSet();
     [WebMethod]
     public DataSet show()
     {
       con.Open();
       adapt = new SqlDataAdapter("Select * from Student", con);
       adapt.Fill(ds, "Student");
       con.Close();
       return ds;
     }
  }
}

                                         .aspx file


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="assWebServic.aspx.cs"
Inherits="WebApplication1.assWebServic1" %>

<!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>

Om Shanti Engg. College - 2012                                                        56
090360116058                                                          Dot Net Technology


     <asp:GridView ID="GridView1" runat="server">
     </asp:GridView>
  </div>
  </form>
</body>
</html>

                                      Code Behind File


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

namespace WebApplication1
{
  public partial class assWebServic1 : System.Web.UI.Page
  {
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
       localhost1.assWebServic obj = new localhost1.assWebServic();
       ds=obj.show();
       GridView1.DataSource = ds;
       GridView1.DataBind();
    }
  }
}




Om Shanti Engg. College - 2012                                                       57
090360116058                     Dot Net Technology


OUTPUT :




Om Shanti Engg. College - 2012                  58
090360116058                                                                     Dot Net Technology


                                 PRACTICAL NO: 16

AIM: Study of ASP.NET administration and configuration tool.

       The Web Site Administration Tool is used to configure the application and security settings of
an ASP.NET Web Application. We can use this tool to perform following tasks:
     Configuring the application security settings, such as authentication and authorization.
     Managing users and roles for an application.
     Creating and managing application settings.
     Configuring SMTP email settings.
     Making an application temporarily offline to update its content and data in a secure manner.
     Adjusting the debugging and tracing settings.
     Defining a default custom error page.
     Selecting providers to use them with the site features, such as membership.

        STEPS TO WEBSITE ADMINISTRATION TOOL:

        1) HOME




Om Shanti Engg. College - 2012                                                                    59
090360116058                     Dot Net Technology


           2) SECURITY




           3) APPLICATION




Om Shanti Engg. College - 2012                  60
090360116058                     Dot Net Technology


       4 ) PROVIDER




Om Shanti Engg. College - 2012                  61

Weitere ähnliche Inhalte

Was ist angesagt?

What is Pure Functional Programming, and how it can improve our application t...
What is Pure Functional Programming, and how it can improve our application t...What is Pure Functional Programming, and how it can improve our application t...
What is Pure Functional Programming, and how it can improve our application t...Luca Molteni
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical FileAshwin Francis
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09HUST
 
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileHarjinder Singh
 
Computer science project work
Computer science project workComputer science project work
Computer science project workrahulchamp2345
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Geeks Anonymes
 
What's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutWhat's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutPaulo Morgado
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentMaty Fedak
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSESujata Regoti
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2zindadili
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2Mouna Guru
 

Was ist angesagt? (20)

What is Pure Functional Programming, and how it can improve our application t...
What is Pure Functional Programming, and how it can improve our application t...What is Pure Functional Programming, and how it can improve our application t...
What is Pure Functional Programming, and how it can improve our application t...
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
syed
syedsyed
syed
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
ASP.NET
ASP.NETASP.NET
ASP.NET
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09
 
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
 
Cs practical file
Cs practical fileCs practical file
Cs practical file
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
What's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutWhat's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOut
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and Reagent
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
C++11
C++11C++11
C++11
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 

Ähnlich wie Hems

data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1Teksify
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016STX Next
 
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfC# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfssuserc77a341
 
Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.Mumbai B.Sc.IT Study
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...Phil Calçado
 
Lecture 09 high level language
Lecture 09 high level languageLecture 09 high level language
Lecture 09 high level language鍾誠 陳鍾誠
 
Net practicals lab mannual
Net practicals lab mannualNet practicals lab mannual
Net practicals lab mannualAbhishek Pathak
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 

Ähnlich wie Hems (20)

C# Lab Programs.pdf
C# Lab Programs.pdfC# Lab Programs.pdf
C# Lab Programs.pdf
 
C# Lab Programs.pdf
C# Lab Programs.pdfC# Lab Programs.pdf
C# Lab Programs.pdf
 
C#.net
C#.netC#.net
C#.net
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1
 
P2
P2P2
P2
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfC# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
 
Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.Write a program to show the example of hybrid inheritance.
Write a program to show the example of hybrid inheritance.
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
 
Lecture 09 high level language
Lecture 09 high level languageLecture 09 high level language
Lecture 09 high level language
 
Net practicals lab mannual
Net practicals lab mannualNet practicals lab mannual
Net practicals lab mannual
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 

Hems

  • 1. 090360116058 Dot Net Technology PRACTICAL NO: 1 AIM: Write a program for Arithmetic Calculator using Console & Windows Application in C# & VB.NET. Console Calculator.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSConsoleApplicationCalculator { class Program { static void Main(string[] args) { int a, b, n; Console.WriteLine("Calculator in C# Console Application "); Console.WriteLine("enter the value of A"); a = int.Parse(Console.ReadLine()); Console.WriteLine("enter the value of B"); b = int.Parse(Console.ReadLine()); Console.WriteLine("enter choice n 1 = Addition n 2 = Substraction n 3 = Multiplication n 4 = Division"); n = int.Parse(Console.ReadLine()); Program p = new Program(); if (n == 1) { p.add(a, b); } else if (n == 2) { p.sub(a, b); } else if (n == 3) { p.mul(a, b); } else if (n == 4) { p.div(a, b); } else { Console.WriteLine("YOU ARE ENTERING WRONG CHOICE"); } Console.ReadKey(); } public void add(int a, int b) Om Shanti Engg. College - 2012 1
  • 2. 090360116058 Dot Net Technology { int c; c = a + b; Console.WriteLine("Addition is " + c); } public void sub(int a, int b) { int c; c = a - b; Console.WriteLine("Substraction is " + c); } public void mul(int a, int b) { int c; c = a * b; Console.WriteLine("Multiplication is " + c); } public void div(int a, int b) { int c; c = a / b; Console.WriteLine("Division is " + c); } } } Om Shanti Engg. College - 2012 2
  • 3. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 3
  • 4. 090360116058 Dot Net Technology Console Calculator.vb Module Module1 Sub Main() Dim a, b, c As Integer Console.WriteLine("Enter Value of a") a = Convert.ToInt16(Console.ReadLine()) Console.WriteLine("Enter Value of a") b = Convert.ToInt16(Console.ReadLine()) c = a + b Console.WriteLine("Addition") Console.WriteLine(+c) c = a - b Console.WriteLine("Substraction") Console.WriteLine(+c) c = a * b Console.WriteLine("Multiplication") Console.WriteLine(+c) c = a / b Console.WriteLine("Division") Console.WriteLine(+c) Console.ReadKey() End Sub End Module Om Shanti Engg. College - 2012 4
  • 5. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 5
  • 6. 090360116058 Dot Net Technology Windows Calculator.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace VBWindowsFormsApplicationCalculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Button1_Click(object sender, EventArgs e) { txtAns.Text = (Convert.ToInt32(txtA.Text) + Convert.ToInt32(txtB.Text)).ToString(); } private void Button2_Click(object sender, EventArgs e) { txtAns.Text = (Convert.ToInt32(txtA.Text) - Convert.ToInt32(txtB.Text)).ToString(); } private void Button3_Click(object sender, EventArgs e) { txtAns.Text = (Convert.ToInt32(txtA.Text) * Convert.ToInt32(txtB.Text)).ToString(); } private void Button4_Click(object sender, EventArgs e) { txtAns.Text = (Convert.ToInt32(txtA.Text) / Convert.ToInt32(txtB.Text)).ToString(); } } } Om Shanti Engg. College - 2012 6
  • 7. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 7
  • 8. 090360116058 Dot Net Technology Windows Calculator.vb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox3.Text = Convert.ToInt32(TextBox1.Text) + Convert.ToInt32(TextBox2.Text) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox3.Text = Convert.ToInt32(TextBox1.Text) - Convert.ToInt32(TextBox2.Text) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox3.Text = Convert.ToInt32(TextBox1.Text) * Convert.ToInt32(TextBox2.Text) End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox3.Text = Convert.ToInt32(TextBox1.Text) / Convert.ToInt32(TextBox2.Text) End Sub End Class Om Shanti Engg. College - 2012 8
  • 9. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 9
  • 10. 090360116058 Dot Net Technology PRACTICAL NO: 2 AIM: Implement a C# Application to Study Inheritance , Constructor and Overloading. Inheritance.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSConsoleInheritance { class Program { static void Main(string[] args) { Console.WriteLine("Inheritance Programn"); Console.WriteLine("Creating Object of Derive classn"); Derive d=new Derive(); Console.WriteLine("Calling Base class method"); d.Display(); Console.WriteLine("Calling Derive class method"); d.Print(); Console.ReadKey(); } } class BaseClass { public void Display() { Console.WriteLine("This is Base class Display() methodn"); } } class Derive :BaseClass { public void Print() { Console.WriteLine("This is derive class Print() method"); } } } Om Shanti Engg. College - 2012 10
  • 11. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 11
  • 12. 090360116058 Dot Net Technology ConstuctorOverloding.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSConsoleConstructorOverLoading { class Program { public Program() { Console.WriteLine("This is Default Constructorn"); } public Program(String nm) { Console.WriteLine("This is one Parameter Constructor"); Console.WriteLine("My Name is : " + nm + "n"); } public Program(int a, string nm) { Console.WriteLine("This is two Parameter Constructor"); Console.WriteLine("My Name is : " + nm + " and i am : " + a + " years old "); } ~Program() { Console.WriteLine("I am calling Destructor"); } public static void Main(string[] args) { Console.WriteLine("This is Costructor and Destructor in C#n"); Program prg = new Program(); Program prg1 = new Program("abc"); Program prg2 = new Program(20, "abc"); Console.ReadKey(); } } } Om Shanti Engg. College - 2012 12
  • 13. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 13
  • 14. 090360116058 Dot Net Technology PRACTICAL NO: 3 AIM:Write a Programm to Demostrate the use of property and indexer. Read & Write Property.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSConsoleProperty { class Program { private string BookName = "abc"; private int BookPrice = 500; public string MyBookName { get { return BookName; } set { BookName = value; } } public int MyBookPrice { get { return BookPrice; } set { BookPrice = value; } } public override string ToString() { return ("BookName is : " + BookName + " Price is : " + BookPrice); } static void Main(string[] args) { Program p = new Program(); Console.WriteLine("This is Read & Write Property Programn"); Console.WriteLine("Default values is :"); Console.WriteLine(p+"n"); p.BookName = ".net Black Book"; p.BookPrice = 450; Console.WriteLine("Changed Value is :"); Console.WriteLine(p); Console.ReadKey(); } } } Om Shanti Engg. College - 2012 14
  • 15. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 15
  • 16. 090360116058 Dot Net Technology Read Only Property.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSConsoleProperty2 { class ReadOnly { private string BookName = "abc"; private int BookPrice = 500; public ReadOnly() { } public ReadOnly(String Name,int Price) { BookName = Name; BookPrice = Price; } public string MyBookName { get { return BookName; } } public int MyBookPrice { get { return BookPrice; } } public override string ToString() { return ("BookName is : " + BookName + " and Price is : " + BookPrice); } static void Main(string[] args) { ReadOnly p = new ReadOnly(); Console.WriteLine("This is Read only Propertyn"); Console.WriteLine("Default values is :"); Console.WriteLine(p + "n"); ReadOnly p1 = new ReadOnly(".net Black Book", 450); Console.WriteLine("Changed Value is :"); Console.WriteLine(p1); Console.ReadKey(); } } } Om Shanti Engg. College - 2012 16
  • 17. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 17
  • 18. 090360116058 Dot Net Technology Static Property.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSConsoleProperty3 { class Static { static void Main(string[] args) { Console.WriteLine("Static Property Programn"); Console.WriteLine("Number of Object : {0}",CounterClass.NumberOfObject); CounterClass Object1 = new CounterClass(); Console.WriteLine("Number of Object : {0}", CounterClass.NumberOfObject); CounterClass Object2 = new CounterClass(); Console.WriteLine("Number of Object : {0}", CounterClass.NumberOfObject); CounterClass Object3 = new CounterClass(); Console.WriteLine("Number of Object : {0}", CounterClass.NumberOfObject); Console.ReadKey(); } } public class CounterClass { private static int n = 0; public CounterClass() { n++; } public static int NumberOfObject { get { return n; } set { n = value; } } } } Om Shanti Engg. College - 2012 18
  • 19. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 19
  • 20. 090360116058 Dot Net Technology Indexer.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace indexer { class indexers { int[] a = new int[3]; public int this[int index] { get { if (index < 0 && index > 3) { return 0; } else { return a[index]; } } set { a[index] = value; } } } class Program { static void Main(string[] args) { Console.WriteLine("This is indexer Programn"); indexers i = new indexers(); i[0] = 100; i[1] = 200; i[2] = 300; for (int j = 0; j <= 2; j++) { Console.WriteLine("Value is : " + i[j]); } Console.WriteLine("Changing values"); i[0] = 101; i[1] = 202; i[2] = 303; for (int j = 0; j <= 2; j++) { Console.WriteLine("Value is : " + i[j]); } Console.ReadKey(); } } } Om Shanti Engg. College - 2012 20
  • 21. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 21
  • 22. 090360116058 Dot Net Technology PRACTICAL NO: 4 AIM: Write a Program for explaining events and Delegates in C# .NET. Events.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace events { public delegate void eventhandler(); class Program { public static event eventhandler show; static void Main(string[] args) { Console.WriteLine("This is events Programn"); show += new eventhandler(Dog); show += new eventhandler(Cat); show += new eventhandler(Mouse); show += new eventhandler(Mouse); show.Invoke(); Console.ReadKey(); } static void Dog() { Console.WriteLine("Dog"); } static void Cat() { Console.WriteLine("Cat"); } static void Mouse() { Console.WriteLine("Mouse"); } } } Om Shanti Engg. College - 2012 22
  • 23. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 23
  • 24. 090360116058 Dot Net Technology Delegates.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace delegates { class Program { public delegate int calci(int i, int j); public static int add(int a, int b) { return a + b; } public static int sub(int a, int b) { return a - b; } public static int mul(int a, int b) { return a * b; } public static int div(int a, int b) { return a / b; } static void Main(string[] args) { Console.WriteLine("This is delegates Programn"); calci c; c = add; Console.WriteLine("add {0}", c.Invoke(50, 20)); c = sub; Console.WriteLine("sub {0}", c.Invoke(100, 20)); c = mul; Console.WriteLine("mul {0}", c.Invoke(50, 25)); c = div; Console.WriteLine("div {0}", c.Invoke(30, 30)); Console.ReadKey(); } } } Om Shanti Engg. College - 2012 24
  • 25. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 25
  • 26. 090360116058 Dot Net Technology PRACTICAL NO: 5 AIM: Implement Windows Form based application using controls like menus, dialog and tool tip etc. Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click End Sub Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) End Sub Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click End Sub Private Sub ProjectToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProjectToolStripMenuItem.Click End Sub Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click End Sub Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click End Sub End Class Om Shanti Engg. College - 2012 26
  • 27. 090360116058 Dot Net Technology OUTPUT : . Om Shanti Engg. College - 2012 27
  • 28. 090360116058 Dot Net Technology PRACTICAL NO: 6 AIM: Implement a VB 2008 Application to study Error Handling. Error Handling.cs Module Module1 Sub Main() Dim a As Integer Dim b As Integer = 1 Dim c As Integer = 0 Try a = b c Catch exc As Exception Console.WriteLine("A run-time error occurred") Finally Console.ReadLine() End Try End Sub End Module Om Shanti Engg. College - 2012 28
  • 29. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 29
  • 30. 090360116058 Dot Net Technology PRACTICAL NO: 7 AIM: Implement concepts of Inheritance, visual inheritance and Interface in windows application. Public Interface person Sub setnum(ByVal n1 As Double, ByVal n2 As Double) Function getsum() As Double End Interface Public Class employee Implements person Dim s1 As Double Public Function getsum() As Double Implements person.getsum Return s1 End Function Public Sub setnum(ByVal n1 As Double, ByVal n2 As Double) Implements person.setnum s1 = n1 + n2 End Sub Public Sub substraction(ByVal n1 As Double, ByVal n2 As Double) Dim d3 As Double = n1 - n2 System.console.writeline("The substraction interface is: " & d3) End Sub End Class Public Class demo Inherits employee Public Sub mul(ByVal n1 As Double, ByVal n2 As Double) Dim d3 As Double= n1 * n2 System.Console.WriteLine("The multiplication using inheritance is : " & d3) End Sub End Class Module Module1 Sub Main() Dim d As New employee() Dim d5 As New demo() Console.WriteLine("Enter a digit:") Dim d1 As Double = CDbl(Console.ReadLine()) Console.WriteLine("Enter a digit:") Dim d2 As Double = CDbl(Console.ReadLine()) d.setnum(d1, d2) System.Console.WriteLine("The sum using interface is: " & d.getsum) d5.substraction(d1, d2) System.console.writeline() d5.mul(d1, d2) End Sub End Module Om Shanti Engg. College - 2012 30
  • 31. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 31
  • 32. 090360116058 Dot Net Technology PRACTICAL NO: 8 AIM: Use Dataset, Data Reader, XML Reader & Data Sources (SQL, Object & XML) with Any Windows or Web Application. DataSet using System; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; namespace WebApplication1 { public partial class assDataset : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=HARDIK- B652B097SQLEXPRESS;Initial Catalog=db1;Integrated Security=True"); SqlDataAdapter adapt; DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { con.Open(); adapt = new SqlDataAdapter("select * from Employee", con); adapt.Fill(ds, "Employee"); con.Close(); } } } DataReader using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; namespace WebApplication1 { public partial class assrreader : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=HARDIK- B652B097SQLEXPRESS;Initial Catalog=db2;Integrated Security=True"); SqlCommand cmd; SqlDataReader reader; String str; protected void Page_Load(object sender, EventArgs e) { con.Open(); Om Shanti Engg. College - 2012 32
  • 33. 090360116058 Dot Net Technology cmd = new SqlCommand("Select * from Employee", con); reader = cmd.ExecuteReader(); reader.Close(); con.Close(); } } } XMLReader using System; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; namespace WebApplication1 { public partial class assXMLReader : System.Web.UI.Page { DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { ds.ReadXml(Server.MapPath("~/assXML.xml")); } } } Om Shanti Engg. College - 2012 33
  • 34. 090360116058 Dot Net Technology PRACTICAL NO: 9 AIM: Use Data Controls like Data List, Grid View, Detail View, Repeater and List Bound Control .aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ass14.aspx.cs" Inherits="WebApplication1.ass14" %> <!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 style="font-weight: 700"> <h2>DataList Control</h2> <asp:DataList ID="DataList1" runat="server"> <ItemTemplate> Student name:<%#Eval("Name") %><br />Roll No:<%#Eval("Roll_No") %><br />Email ID:<%#Eval("EmailId") %> </ItemTemplate> <SeparatorTemplate> <hr /> </SeparatorTemplate> <AlternatingItemTemplate> Student name:<%#Eval("Name") %><br />Roll No:<%#Eval("Roll_No") %><br />Email ID:<%#Eval("EmailId") %> </AlternatingItemTemplate> </asp:DataList> <h2>GridView Control</h2> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> <br /> <h2>DetailsView Control</h2> <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="EmpId" DataSourceID="SqlDataSource1" > <Fields> <asp:BoundField DataField="EmpId" HeaderText="EmpId" ReadOnly="True" SortExpression="EmpId" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Salary" HeaderText="Salary" SortExpression="Salary" /> </Fields> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db2ConnectionString %>" SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource> Om Shanti Engg. College - 2012 34
  • 35. 090360116058 Dot Net Technology <br /> <h2>Repeater Control</h2> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table border="1"> <tr> <th>StudName</th> <th>RollNo</th> <th>EmailID</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%#Eval("Name") %></td> <td><%#Eval("Roll_No") %></td> <td><%#Eval("EmailId") %></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <br /> <h2>ListView Control</h2> <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> Name:<%#Eval("Name") %><dd>Salary:<%#Eval("Salary") %></dd> </ItemTemplate> </asp:ListView> </div> </form> </body> </html> Om Shanti Engg. College - 2012 35
  • 36. 090360116058 Dot Net Technology Code Behind File using System; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; namespace WebApplication1 { public partial class ass14 : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=HARDIK- B652B097SQLEXPRESS;Initial Catalog=db1;Integrated Security=True"); SqlDataAdapter adapt; DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { con.Open(); adapt = new SqlDataAdapter("Select * from Student", con); adapt.Fill(ds, "Student"); DataList1.DataSource = ds; DataList1.DataBind(); GridView1.DataSource = ds; GridView1.DataBind(); Repeater1.DataSource = ds; Repeater1.DataBind(); con.Close(); } } } Om Shanti Engg. College - 2012 36
  • 37. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 37
  • 38. 090360116058 Dot Net Technology PRACTICAL NO: 10 AIM: Implement web application using ASP.NET with web control. .aspx file <%@ Page Language="C#" AutoEventWireup="tr ue" CodeBehind="Pizza.aspx.cs" Inherits="WebApplication1.Pizza" %> <!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> <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Pizza</h2><br /> <asp:CheckBoxList ID="CheckBoxList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True" onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" RepeatColumns="2"> <asp:ListItem>Italian(500)</asp:ListItem> <asp:ListItem>Maxican(1000)</asp:ListItem> <asp:ListItem>Indian(1500)</asp:ListItem> <asp:ListItem>Special(2500)</asp:ListItem> </asp:CheckBoxList> <h2>&nbsp;</h2> <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Toping</h2> <asp:CheckBox ID="CheckBox5" runat="server" Text="Cheez(200/piece)" AutoPostBack="True" /> <asp:CheckBox ID="CheckBox6" runat="server" style="z-index: 1; left: 179px; top: 247px; position: absolute" Text="Butter(15/piece)" AutoPostBack="True" /><br /> <asp:CheckBox ID="CheckBox7" runat="server" Text="Bans(180/piece)" AutoPostBack="True" /> <asp:CheckBox ID="CheckBox8" runat="server" style="z-index: 1; left: 179px; top: 275px; position: absolute" Text="Milk(180/piece)" AutoPostBack="True" /> <br /> <br /> <br /> <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select mode of eating</h2> <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" GroupName="a" Text="Eat" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" GroupName="a" Text="Delivery(1000)" /> Om Shanti Engg. College - 2012 38
  • 39. 090360116058 Dot Net Technology <br /> <br /> &nbsp;<br /> <asp:Button ID="Button1" runat="server" Text="Calculate" onclick="Button1_Click" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </div> </form> </body> </html> Code Behind File using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class Pizza : System.Web.UI.Page { int amt, toping,cnt; protected void Page_Load(object sender, EventArgs e) { } protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) { amt = 0; for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[0].Selected) { cnt += 1; amt += 500; } if (CheckBoxList1.Items[1].Selected) { cnt += 1; amt += 1000; } if (CheckBoxList1.Items[2].Selected) { cnt += 1; amt += 1500; } if (CheckBoxList1.Items[3].Selected) { cnt += 1; amt += 2500; } ViewState["cnt"] = cnt; ViewState["amt"] = amt; } } Om Shanti Engg. College - 2012 39
  • 40. 090360116058 Dot Net Technology protected void Button1_Click(object sender, EventArgs e) { toping = 0; if (CheckBox5.Checked) toping+=(int)ViewState["cnt"]*200; if (CheckBox6.Checked) toping += (int)ViewState["cnt"] * 15; if (CheckBox7.Checked) toping += (int)ViewState["cnt"] * 180; if (CheckBox8.Checked) toping += (int)ViewState["cnt"] * 180; int tot = (int)ViewState["amt"] + toping; if (RadioButton1.Checked) Label1.Text = "Your total bill for pizza is" + tot; } } } Om Shanti Engg. College - 2012 40
  • 41. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 41
  • 42. 090360116058 Dot Net Technology PRACTICAL NO: 11 AIM: Write a code for web application to provide input validations using Input Valuators. .aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="assVAlidation.aspx.cs" Inherits="WebApplication1.assVAlidation" %> <!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"> .style1 { text-decoration: underline; } </style> </head> <body> <form id="form1" runat="server"> <div> <strong><span class="style1"><h2>Simple Application Form</h2></span><br class="style1" /> </strong>User Name:&nbsp;&nbsp;&nbsp; <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1">Plz enter your name</asp:RequiredFieldValidator> <br /> <br /> Password:&nbsp;&nbsp;&nbsp; <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2">Plz enter the password</asp:RequiredFieldValidator> <br /> <br /> Retype Password:&nbsp;&nbsp;&nbsp; <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator" ControlToCompare="TextBox2" ControlToValidate="TextBox3">Password does not match</asp:CompareValidator> <br /> <br /> E-Mail:&nbsp;&nbsp;&nbsp; <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox4" Om Shanti Engg. College - 2012 42
  • 43. 090360116058 Dot Net Technology ValidationExpression="w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*">Not valid</asp:RegularExpressionValidator> <br /> <br /> Age:&nbsp;&nbsp;&nbsp; <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="RangeValidator" ControlToValidate="TextBox5" MaximumValue="40" MinimumValue="20" Type="Integer">The age should be between 20 to 40</asp:RangeValidator> <br /> <br /> Referrer Code:&nbsp;&nbsp;&nbsp; <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ControlToValidate="TextBox6">Try a string that starts from 014</asp:CustomValidator> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Button ID="Button1" runat="server" Text="Submit" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Button ID="Button2" runat="server" Text="Cancel" /> &nbsp;</div> </form> </body> </html> Om Shanti Engg. College - 2012 43
  • 44. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 44
  • 45. 090360116058 Dot Net Technology PRACTICAL NO: 12 AIM: Create a Web application that illustrates the use of themes and master pages with Site-Map. Main.master <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main.master.cs" Inherits="Main" %> <!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"> <center> <table cellpadding="0" cellspacing="0" style="width:1000px; border: 1px solid black;"> <tr> <td colspan="3" style="height:180px; background-color:Silver; width:1000px; border:1px solid black;" ></td> </tr> <tr> <td colspan="3" style="height:35px; background-color:Gray; width:1000px; border:1px solid black;" > <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"> <Items> <asp:MenuItem Text="Home" Value="Home"></asp:MenuItem> <asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem> <asp:MenuItem Text="Contact Us" Value="Contact Us"></asp:MenuItem> <asp:MenuItem Text="Services" Value="Services"></asp:MenuItem> </Items> </asp:Menu> </td> </tr> <tr style="width:1000px;"> <td style="width:200px; background-color:Green; height:850px;">&nbsp;</td> <td style="width:550px; background-color:Green; height:850px;"> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </td> <td style="width:250px;background-color:Green; height:850px;">&nbsp;</td> </tr> <tr> <td colspan="3" style="height:20px; width:1000px;background-color:Black;"></td> </tr> </table> </center> </form> Om Shanti Engg. College - 2012 45
  • 46. 090360116058 Dot Net Technology </body> </html> .aspx file <%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <p> heeeloo world...!!</p> <p> &nbsp;</p> <p> &nbsp;</p> <p> &nbsp;</p> <p>&nbsp;</p> <p>i am back</p> </asp:Content> Om Shanti Engg. College - 2012 46
  • 47. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 47
  • 48. 090360116058 Dot Net Technology PRACTICAL NO: 13 AIM: Create a Web Application in ASP.NET using various CSS. Cssdemo1(.css file) /* header start */ .main_bg { width:100%; background:url(../images/homebg_header.gif) repeat-x left top; margin:0 auto; } .header_image { width:1003px; height:1153px; background-color:Teal; margin:0 auto; } .bottom_image { width:1003px; height:153px; background-color:Silver; margin:top 153px; } Cssdemo2(.css file) /* general top nav */ .top_links { width:295px; float:right; margin:15px 0 0 0; } .top_links ul { list-style:none; } .top_links ul li { float:left; display:block; } .top_links ul li a { text-decoration:none; Om Shanti Engg. College - 2012 48
  • 49. 090360116058 Dot Net Technology color:#4E4E4E; padding:0 10px 0 10px; font-size:12px; } .top_links ul li a:hover { text-decoration:none; color:#8B8B8B; } .nav { float:right; width:550px; padding:23px 0 0 0; display:block; } .aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeFile="cssdemo.aspx.cs" Inherits="cssdemo" %> <!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>css demo</title> <link href="css/cssdemo1.css" rel="stylesheet" type="text/css" /> <link href="css/cssdemo2.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div class="header_image"> <div class="bottom_image"> <div class="header"> This is header part.... <div class="top_links"> <ul class="style3" dir="ltr" type="disc"> <li> <div class="menu_list"> <ul> <li> <a href="#">languages<img src="images/arrow-bullet.gif" alt="global list" width="8" height="4" /> </li> </a> <!--<![endif]--> <!--[if lte IE 6]><table cellpadding="0" cellspacing="0" border="0"><tr><td><![endif]--> <ul> <li><a target="_blank" href="http://www.freedomdesigns.in">INDIA</a></li> Om Shanti Engg. College - 2012 49
  • 50. 090360116058 Dot Net Technology <li><a target="_blank" href="http://www.freedomdesigns.in">UK</a></li> </ul> </div> </li> </ul> <br /> </form> </body> </html> Om Shanti Engg. College - 2012 50
  • 51. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 51
  • 52. 090360116058 Dot Net Technology PRACTICAL NO: 14 AIM: Implement the concept of state management in a web application. .asax file(Global Application file) using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; namespace WebApplication1 { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { Application["count"] = 0; } protected void Session_Start(object sender, EventArgs e) { } protected void Application_BeginRequest(object sender, EventArgs e) { } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } protected void Application_Error(object sender, EventArgs e) { } protected void Session_End(object sender, EventArgs e) { } protected void Application_End(object sender, EventArgs e) { } } } .aspx file using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class WebForm3 : System.Web.UI.Page Om Shanti Engg. College - 2012 52
  • 53. 090360116058 Dot Net Technology { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Application.Lock(); Application["count"] = (int)Application["count"] + 1; Response.Write("Visitor No.=" + Application["count"]); Application.UnLock(); } } protected void Button1_Click(object sender, EventArgs e) { Session["name"] = TextBox1.Text; Session["pwd"] = TextBox2.Text; Response.Redirect("NextPage.aspx"); } } } Code Behind File using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class WebForm3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Application.Lock(); Application["count"] = (int)Application["count"] + 1; Response.Write("Visitor No.=" + Application["count"]); Application.UnLock(); } } protected void Button1_Click(object sender, EventArgs e) { Session["name"] = TextBox1.Text; Session["pwd"] = TextBox2.Text; Response.Redirect("NextPage.aspx"); } } } Om Shanti Engg. College - 2012 53
  • 54. 090360116058 Dot Net Technology NextPage.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class NextPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write("Welcome " + Session["name"] + ". Your password is " + Session["pwd"]); } } } Om Shanti Engg. College - 2012 54
  • 55. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 55
  • 56. 090360116058 Dot Net Technology PRACTICAL NO: 15 AIM: Implement code in ASP.NET that creates and consumes Web service. .asmx file(WebService) using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data.SqlClient; namespace WebApplication1 { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class assWebServic : System.Web.Services.WebService { SqlConnection con=new SqlConnection("Data Source=HARDIK- B652B097SQLEXPRESS;Initial Catalog=db1;Integrated Security=True"); SqlDataAdapter adapt; DataSet ds=new DataSet(); [WebMethod] public DataSet show() { con.Open(); adapt = new SqlDataAdapter("Select * from Student", con); adapt.Fill(ds, "Student"); con.Close(); return ds; } } } .aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="assWebServic.aspx.cs" Inherits="WebApplication1.assWebServic1" %> <!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> Om Shanti Engg. College - 2012 56
  • 57. 090360116058 Dot Net Technology <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </div> </form> </body> </html> Code Behind File using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class assWebServic1 : System.Web.UI.Page { DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { localhost1.assWebServic obj = new localhost1.assWebServic(); ds=obj.show(); GridView1.DataSource = ds; GridView1.DataBind(); } } } Om Shanti Engg. College - 2012 57
  • 58. 090360116058 Dot Net Technology OUTPUT : Om Shanti Engg. College - 2012 58
  • 59. 090360116058 Dot Net Technology PRACTICAL NO: 16 AIM: Study of ASP.NET administration and configuration tool. The Web Site Administration Tool is used to configure the application and security settings of an ASP.NET Web Application. We can use this tool to perform following tasks:  Configuring the application security settings, such as authentication and authorization.  Managing users and roles for an application.  Creating and managing application settings.  Configuring SMTP email settings.  Making an application temporarily offline to update its content and data in a secure manner.  Adjusting the debugging and tracing settings.  Defining a default custom error page.  Selecting providers to use them with the site features, such as membership. STEPS TO WEBSITE ADMINISTRATION TOOL: 1) HOME Om Shanti Engg. College - 2012 59
  • 60. 090360116058 Dot Net Technology 2) SECURITY 3) APPLICATION Om Shanti Engg. College - 2012 60
  • 61. 090360116058 Dot Net Technology 4 ) PROVIDER Om Shanti Engg. College - 2012 61