dot net practical file

Upload: dharmendra-kumar

Post on 03-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Dot Net Practical File

    1/41

    1

    Practical FileOf

    DOT NET FRAMEWORK

    Submitted by: Under the guidance of:

    Ashish Bhandari Mrs. Rubinder Kaur

    81103113008

    It-6thSem.

  • 8/12/2019 Dot Net Practical File

    2/41

    2

    Aim 1: M icrosoft Visual Studio 2008 I nstal lation

    This Windows 7 tutorial is going to show how to install Visual Studio 2008 on Windows 7.

    I'll install Microsoft Visual Studio 2008 Team Suite Edition on Microsoft Windows 7 Ultimate.

    I had a clean install of Windows 7 on my new computer and I tried to install Visual Studio 2008

    on Windows 7. I managed installing VS successfully with a simple and plain installation process.

    I have an .iso file of the VSTS2008 Team Suite and extracted it on a folder. Within the extracted

    folder the installation file is setup.exe install file.

    When I double click to run the setup.exe file, the following User Account Control (UAC) screen

    is asking me if I allow the setup.exe program to run.

    Click "Yes" to continue with Visual Studio 2008 installation further on Windows 7.

    The first screen in Visual Studio 2008 Setup is the below setup dialog screen.

  • 8/12/2019 Dot Net Practical File

    3/41

  • 8/12/2019 Dot Net Practical File

    4/41

    4

    If you agree to submit anonymous information about your Visual Studio setup experiences to

    Microsoft, mark the checkbox "Yes, send information about my setup experiences to Microsoft

    Corporation."

    The next screen in the VS 2008 setup wizard requests you to confirm that you have read and

    accept the license terms.

    You should also supply the Microsoft Visual Studio 2008 product key.

  • 8/12/2019 Dot Net Practical File

    5/41

    5

    This step is which you select the Visual Studio 2008 features to setup. You have two quick

    options first the default installation and the full installation.

    Default installation will install common and recommended VS2008 features on the other hand

    full installation will install all the features of MS Visual Studio 2008.

  • 8/12/2019 Dot Net Practical File

    6/41

    6

    You can configure VS2008 installation in more detail by selecting the third option, Custominstallation.

    The VS 2008 installation path is default "C:\Program Files\Microsoft\Visual Studio 9.0\" andcannot be altered.

    You can see the required disk space for each install option on the right bottom part of the setup

    wizard.

  • 8/12/2019 Dot Net Practical File

    7/41

    7

    The Microsoft VSTS 2008 installation process starts as seen in the below screenshot.

  • 8/12/2019 Dot Net Practical File

    8/41

  • 8/12/2019 Dot Net Practical File

    9/41

    9

    After the VS 2008 installation is completed successfully on Microsoft Windows 7 Ultimate

    operating system, it is time for an update or installing the product documentation like help

    documents, tutorials and samples, etc.

  • 8/12/2019 Dot Net Practical File

    10/41

    10

    I will install MSDN documentation for VS2008 after installing service pack for VS2008

    installation. I want to show you the below screenshot that I have installed the Visual Studio 2008

    on my Windows 7 computer with its all features selected without any problem .

  • 8/12/2019 Dot Net Practical File

    11/41

    11

    And here is the start page of the Microsoft Visual Studio Team System 2008 IDE with general

    development settings is selected running successfully on Windows 7.

  • 8/12/2019 Dot Net Practical File

    12/41

    12

    AIM2 : An I ntroduction to the .net framework?

    The .NET Framework is an integral Microsoft Windows component designed to support next-

    generation applications and services. Many fundamentals of the .NET Framework will be

    familiar to developers who have worked in other object-oriented development environments.

    Microsoft's .NET framework introduces a whole new way of programming the Microsoft

    platform. Microsoft developers are primarily concerned with threads and memory (that's

    basically the API programming model). This model carried over to all areas of development,

    including Web development, placing a heavy burden upon programmers. .NET is built upon the

    notion of managed types. Developers writing classic Windows code (and Web code) wrote

    classes using C++ or Visual Basic. In many ways, types are similar to the notion of the C++ class

    in that types are units of state with functionality attached to them. However, the similarity ends

    there. Whereas it was incumbent upon the developer to manage instances of classes, types are

    managed completely by the .NET runtime servicesthe Common Language Runtime (CLR).Because the CLR takes over managing memory and threads, developers are much more at liberty

    to concentrate on the actual application (rather than chasing down errant pointers, memory leaks,

    and unexplained crashes).

    ASP.NET introduces runtime services and a well-engineered class library for greatly enhancing

    Web development. In a way, classic ASP was sort of taped onto the IIS/ISAPI architecture

    without any real organic thought as to how early design decisions would affect developers later

    on. Well, now it's later on and classic ASP.NET's warts have become fairly obvious.

    ASP.NET 1.0 and 1.1 provided a significant number of features, including:

    An object-oriented framework for defining applications Separation of user interface declarations (HTML) and application logic Compiled code for executing application logic Configurable session state management Built-in data caching Built-in content caching A well-defined UI componentization architecture High-level components for managing data formatting (grids, lists, text boxes) Built-in program tracing and diagnostics Built-in user input validation

  • 8/12/2019 Dot Net Practical File

    13/41

    13

    An easy-to-use custom authentication mechanism Solid integration with ADO.NET (the .NET database story) Excellent support for Web Services Zero reliance on the Component Object Model An extensible pipeline with many places in which a request can be intercepted ASP.NET 1.0 set the stage for many developers both moving into Web development and

    moving to the Microsoft Platform.

    ASP.NET 2.0 builds upon ASP.NET 1.0 and 1.1 by providing a number of new features in

    addition to what already existed with ASP.NET 1.0. These features include

    Master Pages and Skins Declarative data-binding Provider pattern model New cache features Membership controls Personalization controls Support for Web Parts Programmable configuration Administration tools New compilation model All the features of ASP.NET 1.0/1.1 are still there. However, these new features make

    ASP.NET an even more compelling platform for creating Web sites.

    A Word About the .NET Runtime

    ASP.NET 2.0 is built upon Microsoft's Common Language Runtime. In its earliest days,

    programming Windows involved interacting with the operating system at a very intimate level.

    For example, getting a Window to show up on a screen took many lines of C code. In addition,

    Windows included a rudimentary component technologyraw Dynamic Link Libraries.

    Dynamic Link Libraries (DLLs) represent a necessary technology to enable composing systems

    dynamicallythat is, to assemble applications from several disparate binary components.

  • 8/12/2019 Dot Net Practical File

    14/41

    14

    However, DLLs by themselves are not sufficient for composing systems reliablyprimarily

    because it's very difficult to manage multiple versions of a component (a DLL).

    During the mid-90's, the Component Object Model (COM) emerged as a way to help manage

    multiple versions of a component. By stipulating strict rules about how clients and components

    may interact, COM represented a technology sufficient for composing applications fromdifferent binary components. However, COM faced a few dead ends which became apparent as

    developers began building larger systems.

    First, COM relied on humans following rules to get things to interoperate. For example, COM

    stipulates a rule that once a programmatic interface is published, it must never change. Changing

    a published COM interface after clients begin coding against it will almost certainly bring a

    system to its knees. In addition, COM relied on sometimes obtuse rules as far as managing

    resources. However, the coup de grace for COM was probably the disparate type systems

    involved. That is, COM represented many data types differently for three separate classes of

    developers: C++ developers, Visual Basic developers, and scripting developers. The differentdata type systems made it extremely inconvenient to build systems built from different

    languages. It could be done, but developers had to be very wary when making calls across such

    component boundaries.

    .NET and the Common Language Runtime (the CLR) were developed to solve the dead ends

    appearing in COM near the end of the last century. When you choose to buy into the .NET

    runtime, it's like putting your code in a nice hotel room when it runs. For example, the .NET

    runtime loads and manages your code as it runs. Pure memory leaks are a thing of the past

    because the runtime collects garbage when necessary. The problem of overrunning array

    boundaries disappears because the .NET runtime keeps careful watch over memory and knowswhen anything is out of place. In addition, the .NET runtime includes a new security model

    making it more difficult to hack into .NET-based software. Finally, the .NET runtime introduces

    a new packaging and deployment model, .NET Assemblies, which helps enforce versioning

    components.

  • 8/12/2019 Dot Net Practical File

    15/41

    15

    Figure 1: .net Framework

    The top layer represents user and program interfaces, and includes Windows Forms, Web Forms,

    Web Services, and Application Services. Windows Forms provide a Win32/64-based user

    interface. Web Forms provide a Web-based user interface. Web Services are the most

    revolutionary program interfaces because they allow programs to communicate over the Internet.

    The Internet-based program interfaces, which include Web Forms and Web Services, are

    implemented by ASP.NET, which is a built-in component of the .NET Framework.

    The middle layer represents the .NET Framework classes, which are universally available across

    multiple languages. The usage of these classes is consistent across all languages included in the

    .NET Framework.

    The base layer represents the common execution platform called the Common Language

    Runtime (CLR). This is the most important component of the .NET Framework. The CLR

    provides support for multiple languages and allows cross-language inheritance. For example, you

    can inherit a class written in Visual Basic from a class written in Visual C++. Thus, with .NET,

    the choice of a programming language simply depends on the user's choice. With .NET, it is

    possible to create applications by using multiple languages. The multiple-language support is

    possible because the CLR provides a common system of data types. In addition, the CLR

    performs the memory management and monitors the complete life cycle of objects, while it

    tracks objects and handles garbage collection.

    Visual Studio .NET (VS.NET) is the first release of the products based on the .NET Framework.

    It includes Visual Basic, Visual C++, and C#. VS.NET provides a common Integrated

    Development Environment (IDE) for all languages. Therefore, developers always work in a

    consistent environment irrespective of the language they use.

  • 8/12/2019 Dot Net Practical File

    16/41

    16

    AIM 3: Famil iar wi th the VS development environment.

    Toolbox

    Page Layout

    Property window

    Toolbox contains all the controls of the form. Just drag and drop the control from thetoolbox to the form.

    Page Layout gives the design of the form appears at the run time. Property window, list the basic attributes of the control. Solution Explorer, it gives the directory structure of the project.

  • 8/12/2019 Dot Net Practical File

    17/41

    17

    AIM 4: Features of .NET

    The following are major features of .NET.

    AssembliesAn assembly is either a .DLL or .EXE that forms a part of anapplication.It contains MSIL code

    that is executed by CLR. The following are other important points related to an assembly:

    1. It is the unit on which permissions are granted.2. Every assembly contains a version3. Assemblies contain interfaces and classes. They may also contain other resources

    such as bitmaps, file etc.4. Every assembly contains assembly metadata, which contains information about

    assembly. CLR uses this information at the time of executing assembly.5. Assemblies may be either private, which are used only by the application to which

    they belong or Global assemblies, which are used by any application in the

    system.

    6. Two assemblies of the same name but with different versions can run side-by-sideallowingapplications that depend on a specific version to use assembly of that

    version.

    The four parts of an assembly are:

    Assembly Manifest- Contains name, version, culture, and information about referenced

    assemblies.

    Type metadata - Contains information about types defined in the assembly.

    MSIL- MSIL code.

    Resources- Files such as BMP or JPG file or any other files required by application..

    Common Type SystemCommon Type System (CTS) specifies the rules related todata types that languages must follow.As programs written in all languages are ultimately converted to MSIL, data types in all

    languages must be convertible to certain standard data types.

    CTS is a part of cross-languageintegration,which allows classes written in one language to be

    used and extended by another language.

    http://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=64340&ts=20040122055531&redir=http://www61.overture.com/d/sr/?xargs=02u3hs9yoaj12POzCDhBDN%2F2iWg22LsXwtpDwpdI%2Bu8YyWSRDAUTDv8kHDj3FW1d2jb5m%2Ftv5mp%2BUW6Iff7%2FQw8AXnl0KBiJYjPCNwSLtwcIxLtX6KR6H26DTYDu729occtttvfr%2FvNuwfpGxWgwrAsqUP4oyeXOywFwBXZXRoxyWcHFONk7znnTghwpuPFNiC2WhdcqxJwWoDGy7DyuaMtLPp7%2FEzjzP1noyY8IjWqrpUlSw1CSu1LXSCBZlTdYL%2FcvWGJZ5ZrOnfLB8kRls%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=23001&ts=20040122055531&redir=http://www60.overture.com/d/sr/?xargs=02u3hs9yoaj12POzCDhBDN%2F2iWwP3CjwWFSkHil8j6RxgEsoCGLon%2B%2FxI4jylW1d2jb5lP1nCzYw9z8mLoOv7N3IlpZtDAQ8IbbhFRhpvwcIxzcmFOtzZu2HmxHNj53Oh368%2B%2F8rhdtbgvz6FWsqmqwkuKUlk%2BVslgzg5bZPRqIpLvB5jSxq5TTb0fcct7TDxB0WhdUKwJRmoWD036yuSENkfot%2BPlj%2FsZhxNwYMafurKVqg0Ui8xaYQVoOPnTMd2Olh3J4ywQoXiCCw%2F0refhWw%3D%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=64376&ts=20040122055531&redir=http://www61.overture.com/d/sr/?xargs=02u3hs9yoaj1UOyzCCRRBm%2F2SWAPrF2sQsCbYWO03umKEAkBQqf6OWr3GFyzJ7k93Pw%2F7WhomvWUgRAkjaOgwS4kHhQ4KIFzQjiX6%2Fc2PQP2hxLcPqz%2BBpz2889%2Bt%2FQ9vxfxgSamkrc7WB1Zcb%2BZfG7ieShkNGhZ0Jr5%2Bd84%2BCrT6YqGyqS2FKVRpTYavS%2FKDKfLOVn73QNOQ9TDphEHdo5kaUywFCSloXrEGCb2vawXg3WsqfZkzLOhvlWpmhTQ%3D%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=143849&ts=20040122055531http://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=143849&ts=20040122055531http://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=64376&ts=20040122055531&redir=http://www61.overture.com/d/sr/?xargs=02u3hs9yoaj1UOyzCCRRBm%2F2SWAPrF2sQsCbYWO03umKEAkBQqf6OWr3GFyzJ7k93Pw%2F7WhomvWUgRAkjaOgwS4kHhQ4KIFzQjiX6%2Fc2PQP2hxLcPqz%2BBpz2889%2Bt%2FQ9vxfxgSamkrc7WB1Zcb%2BZfG7ieShkNGhZ0Jr5%2Bd84%2BCrT6YqGyqS2FKVRpTYavS%2FKDKfLOVn73QNOQ9TDphEHdo5kaUywFCSloXrEGCb2vawXg3WsqfZkzLOhvlWpmhTQ%3D%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=23001&ts=20040122055531&redir=http://www60.overture.com/d/sr/?xargs=02u3hs9yoaj12POzCDhBDN%2F2iWwP3CjwWFSkHil8j6RxgEsoCGLon%2B%2FxI4jylW1d2jb5lP1nCzYw9z8mLoOv7N3IlpZtDAQ8IbbhFRhpvwcIxzcmFOtzZu2HmxHNj53Oh368%2B%2F8rhdtbgvz6FWsqmqwkuKUlk%2BVslgzg5bZPRqIpLvB5jSxq5TTb0fcct7TDxB0WhdUKwJRmoWD036yuSENkfot%2BPlj%2FsZhxNwYMafurKVqg0Ui8xaYQVoOPnTMd2Olh3J4ywQoXiCCw%2F0refhWw%3D%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=64340&ts=20040122055531&redir=http://www61.overture.com/d/sr/?xargs=02u3hs9yoaj12POzCDhBDN%2F2iWg22LsXwtpDwpdI%2Bu8YyWSRDAUTDv8kHDj3FW1d2jb5m%2Ftv5mp%2BUW6Iff7%2FQw8AXnl0KBiJYjPCNwSLtwcIxLtX6KR6H26DTYDu729occtttvfr%2FvNuwfpGxWgwrAsqUP4oyeXOywFwBXZXRoxyWcHFONk7znnTghwpuPFNiC2WhdcqxJwWoDGy7DyuaMtLPp7%2FEzjzP1noyY8IjWqrpUlSw1CSu1LXSCBZlTdYL%2FcvWGJZ5ZrOnfLB8kRls%3D
  • 8/12/2019 Dot Net Practical File

    18/41

    18

    Cross-language Interoperability.NET provides support for language interoperability. However, it doesn't mean every

    program written in a language can be used by another language. To enable a program tobe used with other languages, it must be created by following a set of rules called Cross

    Language Specifications (CLS).

    Cross-language inheritance is the ability to create a class in C# from a class created inVB.NET.

    When an exception is raised by a program written in C#, the exception can be handled by

    VB.NET. This kind of exception handling is called cross-language exception handling.

    .NET has brought a set of new features which are to be understood by every programmer

    developingapplications for Windows. There is no way any Windows programmer can

    ignore.NET unless he is desperate to be outdated. Microsoft will provide.NET as part of itsoperating systems in future releases. It is the platform for programmers. It is not new OS from

    Microsoft or a new language. It is the environment for which you develop applications. It is rich

    in terms of features.

    http://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=23269&ts=20040122055531&redir=http://www60.overture.com/d/sr/?xargs=02u3hs9yoaj1VuzTCDhBBm30Vvb2vgbAew1wduUvQ5AR4rdn4kMFJ5KBL7qVNq6qtOzNHrN7D%2F8nYr4W%2BMPbtTGa5kmhECyNZasIhJMT1ohEs9azHHvMzNdRZe4If6uxj22%2Fq8usPkvWfx9tCPkUgjk3Z9rPJwjKIHuEgIUgpUCQl62sac3m8Xmhp2TuTd4itIKbQirKCrn9%2BXlNSVWOpr%2BKo%2Buj4wIXOmbIaLZSqCF5hSpgWXy8S4nfyZlhOVy2YFrKcIzAB%2FaRzZUQ%3D%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=23001&ts=20040122055531&redir=http://www60.overture.com/d/sr/?xargs=02u3hs9yoaj12POzCDhBDN%2F2iWwP3CjwWFSkHil8j6RxgEsoCGLon%2B%2FxI4jylW1d2jb5lP1nCzYw9z8mLoOv7N3IlpZtDAQ8IbbhFRhpvwcIxzcmFOtzZu2HmxHNj53Oh368%2B%2F8rhdtbgvz6FWsqmqwkuKUlk%2BVslgzg5bZPRqIpLvB5jSxq5TTb0fcct7TDxB0WhdUKwJRmoWD036yuSENkfot%2BPlj%2FsZhxNwYMafurKVqg0Ui8xaYQVoOPnTMd2Olh3J4ywQoXiCCw%2F0refhWw%3D%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=23001&ts=20040122055531&redir=http://www60.overture.com/d/sr/?xargs=02u3hs9yoaj12POzCDhBDN%2F2iWwP3CjwWFSkHil8j6RxgEsoCGLon%2B%2FxI4jylW1d2jb5lP1nCzYw9z8mLoOv7N3IlpZtDAQ8IbbhFRhpvwcIxzcmFOtzZu2HmxHNj53Oh368%2B%2F8rhdtbgvz6FWsqmqwkuKUlk%2BVslgzg5bZPRqIpLvB5jSxq5TTb0fcct7TDxB0WhdUKwJRmoWD036yuSENkfot%2BPlj%2FsZhxNwYMafurKVqg0Ui8xaYQVoOPnTMd2Olh3J4ywQoXiCCw%2F0refhWw%3D%3Dhttp://itxt.vibrantmedia.com/al.asp?ipid=111&cc=us&ai=15598777&di=23269&ts=20040122055531&redir=http://www60.overture.com/d/sr/?xargs=02u3hs9yoaj1VuzTCDhBBm30Vvb2vgbAew1wduUvQ5AR4rdn4kMFJ5KBL7qVNq6qtOzNHrN7D%2F8nYr4W%2BMPbtTGa5kmhECyNZasIhJMT1ohEs9azHHvMzNdRZe4If6uxj22%2Fq8usPkvWfx9tCPkUgjk3Z9rPJwjKIHuEgIUgpUCQl62sac3m8Xmhp2TuTd4itIKbQirKCrn9%2BXlNSVWOpr%2BKo%2Buj4wIXOmbIaLZSqCF5hSpgWXy8S4nfyZlhOVy2YFrKcIzAB%2FaRzZUQ%3D%3D
  • 8/12/2019 Dot Net Practical File

    19/41

    19

    AIM 5: Design a calculator with button and textbox

    (with window forms)

    usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;

    namespacecal{publicpartialclassForm1: Form

    {publicForm1()

    {InitializeComponent();

    }stringst = "";stringop = "";floatresult;

    privatevoidbutton1_Click(objectsender, EventArgse){

    st += "1";textBox1.Text = st;

    }

    privatevoidbutton2_Click(objectsender, EventArgse){

    st += "2";textBox1.Text = st;

    }

    privatevoidbutton3_Click(objectsender, EventArgse){

    st += "3";textBox1.Text = st;

    }

    privatevoidbutton4_Click(objectsender, EventArgse){

    st += "4";textBox1.Text = st;

    }

    privatevoidbutton5_Click(objectsender, EventArgse){

    st += "5";textBox1.Text = st;

  • 8/12/2019 Dot Net Practical File

    20/41

  • 8/12/2019 Dot Net Practical File

    21/41

    21

    textBox1.Clear();}

    privatevoidbutton14_Click(objectsender, EventArgse){

    op = "/";result = Convert.ToSingle(textBox1.Text);st = "";button16.Enabled = true;textBox1.Clear();

    }

    privatevoidbutton15_Click(objectsender, EventArgse){

    if(op == "+"){

    result = result + Convert.ToSingle(textBox1.Text);}

    elseif(op == "-"){

    result = result - Convert.ToSingle(textBox1.Text);}

    elseif(op == "*"){

    result = result * Convert.ToSingle(textBox1.Text);}

    elseif(op == "/"){

    if(Convert.ToInt32(textBox1.Text) == 0){

    MessageBox.Show("Cannot Divide By 0");}

    else{

    result = result / Convert.ToSingle(textBox1.Text);}

    }textBox1.Text = result.ToString();st = "";

    }

    privatevoidbutton16_Click(objectsender, EventArgse){

    st += ".";textBox1.Text = st;button16.Enabled = false;

    }

    }}

  • 8/12/2019 Dot Net Practical File

    22/41

    22

    Output:

  • 8/12/2019 Dot Net Practical File

    23/41

    23

    AIM 6:To study Basic Window Controls

    Button:

    Used to start ,stop or interrupt a process

    usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;

    namespacebutton{publicpartialclassForm1: Form

    {publicForm1()

    {InitializeComponent();

    }

    privatevoidbutton1_Click(objectsender, EventArgse){

    MessageBox.Show("U just clicked");}

    }}

    Output:

  • 8/12/2019 Dot Net Practical File

    24/41

  • 8/12/2019 Dot Net Practical File

    25/41

    25

    Combo Box:Displays a drop down list of items. It is used to store multiple items but allows only

    single selection.

    Adding items to Combo Box:

    We use Add( ) method to add items in Combo Box.

    privatevoidForm1_Load(objectsender, EventArgse){

    comboBox1.Items.Add("India");comboBox1.Items.Add("USA");comboBox1.Items.Add("Australia");

    }

    Removing items from Combo Box:

    There are 2 ways to remove items from Combo Box.

    1. Remove: This method is used to remove items text wise.

    comboBox1.Items.Remove("USA");

  • 8/12/2019 Dot Net Practical File

    26/41

    26

    2. RemoveAt: This method is used to remove items index wise i.e. from location.

    comboBox1.Items.RemoveAt(1);

    Both these methods will display the following output:

    Displaying selected Item:

    MessageBox.Show(comboBox1.SelectedItem);

    Count:Counts the no of items.

    Int32total = comboBox1.Items.Count();

    Clear:Deletes all the items.

    comboBox1.Items.Clear();

  • 8/12/2019 Dot Net Practical File

    27/41

    27

    RadioButton:Radio buttons are used for single selection only.

    privatevoidbutton1_Click(objectsender, EventArgse){

    if(radioButton1.Checked == true){

    MessageBox.Show(radioButton1.Text);}

    elseif(radioButton2.Checked == true){

    MessageBox.Show(radioButton2.Text);}

    else{

    MessageBox.Show("Please select a value");

    }}

  • 8/12/2019 Dot Net Practical File

    28/41

  • 8/12/2019 Dot Net Practical File

    29/41

    29

    `Displaying selected Items:

    privatevoidbutton1_Click(objectsender, EventArgse){

    stringst="";for(Int32i = 0; i < checkedListBox1.CheckedItems.Count; i++)

    {st += checkedListBox1.CheckedItems[i].ToString() + " ";

    }MessageBox.Show(st);

    }

  • 8/12/2019 Dot Net Practical File

    30/41

    30

    Displays a list of items and allow single as well as multiple selection. For multiple selection,

    change the property "Selection Mode" of List box to "MultiSimple".

    Adding items to List Box:

    Items can be added in List box in the same way as Checked List Box.

    listBox1.Items.Add("Maths");

    Displaying selected Items:

    privatevoidbutton1_Click(objectsender, EventArgse){

    stringst="";for(Int32i = 0; i < listBox1.SelectedItems.Count; i++)

    {

    st += listBox1.SelectedItems[i].ToString() + " ";}

    MessageBox.Show(st);}

  • 8/12/2019 Dot Net Practical File

    31/41

    31

    AIM7: I ntroduction to the web form in visual studio.

    Before you use any server control to design a Web Forms page, you need to create an

    ASP.NET Web Application project. You can create either a Visual Basic .NET or a C# Web

    Application project, depending on the programming language you want to use.A Web

    Application project is always created on a Web server.

    The steps to create an ASP.NET Web Application project are as follows:

    1. Select Start >Programs >Microsoft Visual Studio 2005 >

    Microsoft Visual Studio 2005 to start Visual Studio.NET.

    2. Select File >New > Website to open the New dialog box.

    3. Select ASP.NET Web Application in the Templates pane.

    4. Specify the project name in the Name box, if necessary.

    5. Specify the name of the computer where you want to create the application, in the

    Location box if necessary, and click OK.A new Web Application project is displayed in the

    designer window, as shown in figure below.

  • 8/12/2019 Dot Net Practical File

    32/41

    32

    When you create a Web Application project, the Application Wizard creates the necessary

    project files along with the page file and code behind class file as described:

    Default.aspx: This page file consists of the user interface for the visual representation of theWeb Forms page. The file has two views, Design and HTML. The default view is Design

    view.

    Design view: This view represents the user interface for the Web Forms page. Youcan place controls directly from the toolbox to the Web Forms page in Design view.

    By default, the page layout of the Web Forms page is Grid Layout. This layout

    enables you to accurately position controls on the page by using the absolute

    coordinates (X,Y) of the page. In addition to Grid Layout, ASP.NET provides

    another page layout, which is called Flow Layout. In Flow Layout, you can add text

    to the page directly in Design mode. You can change the page layout from thedefault Grid Layout to Flow Layout. To do so, right-click the page in Design view

    and select Properties from the context menu. Next, in the DOCUMENT Property

    Pages dialog box, from the Page Layout list box, select Flow Layout.

    HTML view: This view represents the ASP.NET code for the Web Forms page. Toopen HTML view, click the HTML tab in the designer. When the Web Application

    project is a Visual Basic project or a C# project, the scripting language used in the

    HTML page is Visual Basic or C#, respectively.

    Default.aspx.cs or Default.aspx.vb: This file consists of the code to implement programming

    logic in the Web Forms page. You can view the code file by using the Show All Files icon in

    the Solution Explorer window. If the Web Application project is a Visual Basic project, you

    use Visual Basic .NET to implement the programming logic and the code file is called the

    Default.aspx.vb file. Conversely, if the Web Application project is a C# project, you use C#

    to implement the programming logic and the code file is called the Default.aspx.cs file. The

    code file (Default.aspx.cs) appears within the WebForm1.aspx node as shown in figure.

  • 8/12/2019 Dot Net Practical File

    33/41

    33

    AI M 8: Studying the F iles in a Web Forms Project

    The Web form is only one of 11 files Visual Studio .NET generates when it creates a new

    Web forms project. The purpose of each of these project files are described below.

    File name Contains

    AssemblyInfo.vb

    AssemblyInfo.cs

    All of the attributes that are written into thecompiled assembly, including version,

    company name, GUID, and so on.

    Global.asax

    The global events that occur in your Web

    application, such as when the application starts

    or ends. You can have only one Global.asax

    file per project, and it exists in the root folderof the project.

    Global.asax.vb

    Global.asax.cs

    The code used in Global.asax. This file is notshown in Solution Explorer.

    Styles.css

    The style definitions to use for the HTML

    generated by your project. This file appearsonly in Visual Basic .NET projects. For Visual

    C# projects, you can add it manually.

    Web.config

    The settings your Web server uses when

    processing this project. These settings specify

    how errors are reported, what type of userauthentication to use, and so on.

    Projectname.vsdisco

    Descriptions of the Web Services that thisproject provides. This file is used for dynamic

    discovery of Web services (.asmx files)

    included in a Web application. This file is notshown in Solution Explorer.

    WebForm1.aspx The visual description of a Web form.

    WebForm1.aspx.vb

    WebForm1.aspx.cs

    The code that responds to events on the Webform. By default, this file is not shown in

    Solution Explorer.

    WebForm1.aspx.resx

    The Extensible Markup Language (XML)

    resources used by the Web form. This file is

    not shown in Solution Explorer.

    Projectname.vbproj

    Projectname.csproj

    The project files listing the files and settingsused at design time. This file is not shown inSolution Explorer.

    Projectname.vbproj.webinfo

    Projectname.csproj.webinfo

    This file tracks the root virtual folder for the

    Web application. This file is not shown in

    Solution Explorer.

  • 8/12/2019 Dot Net Practical File

    34/41

    34

    The primary types of files that youll add to a Web application project are:

    File extension Project item Description

    .aspx Web form

    Each Web form constitutes an

    ASP.NET Web page in your

    application. Applications canhave one or many Web forms.

    Web forms have code files

    associated with them with the

    file extension .aspx.vb. VisualC# forms have associated

    .aspx.cs files.

    .htm HTML page

    Web pages that dont have

    server code can appear as

    HTML pages in your project.

    .vb or .cs Class or module

    Code that defines objects in

    your application is stored inclasses.

    .ascx Web user control

    User controls that are builtfrom other Web forms and

    server controls in Visual

    Studio .NET.

    .asmx Web service

    Web services that expose

    classes for remote executionover a network, such as the

    Internet.

    .xml XML file

    Data files that store

    information used by your

    application.

    .xsd XML Schema

    Schema files that describe the

    format and constraints toapply to stored data.

    .xslt XML Style SheetFormatting rules to applywhen displaying XML data.

  • 8/12/2019 Dot Net Practical File

    35/41

    35

    AI M 9: Creating the f irst web application.

    At Design time:

    Step 1:Go to the File>New Website > ASP.net website then name the website project

    name.

    Step2:Now drag the Textbox and Button from the toolbox to the web form.

    Step3:Double click on the Button to navigate click event of the Button in coding page.

    Now in write the coding as follows:

    protectedvoidButton1_Click(objectsender, EventArgse){

    TextBox1.Text = System.DateTime.Now.ToString();

    }

  • 8/12/2019 Dot Net Practical File

    36/41

    36

    AIM 10: To make famili ar with the validation control

    in the Web form.

    Working with ASP.NET validation server controls is no different from working with any

    other ASP.NET server controls. Each of these controls allows you to drag and drop it onto a

    design surface or to work with it directly from the code of your ASP.NET page. These

    controls can also be modified so that they appear exactly as you wishensuring the visual

    uniqueness that your applications might require.

    The following table describes the functionality of each of the available validation server

    controls.

    Validation Server Control Description

    RequiredFieldValidator Ensures that the user does not skip a formentry field.

    CompareValidator Allows for comparisons between the userss

    input and another item using a comparison

    operator (equals, greater than, less than, and

    so on).

    RangeValidator Checks the users input based upon a lower-

    and upper-level range of numbers or

    characters.

    RegularExpressionValidator Checks that the users entry matches a

    pattern defined by a regular expression. This

    is a good control to use to check e-mail

    addresses and phone numbers.

    CustomValidator Checks the users entry using custom-coded

    validation logic.

    ValidationSummary Displays all the error messages from the

    validators in one specific spot on the page.

    Validation Causes:

    Validation doesnt just happen; it occurs in response to an event. In most cases, it is a button

    click event.The Button, LinkButton, and ImageButton server controls all have the capability

    to cause a pages formvalidation to initiate. This is the default behavior. Dragging and

    dropping a Button server control ontoyour form will give you the following initial result:

  • 8/12/2019 Dot Net Practical File

    37/41

    37

    If you have multiple buttons on an ASP.NET page, and you dont want each and every button

    to initiatethe form validation, you can set the CausesValidation property to False for all the

    buttons you wantto ignore the validation process (for example, a forms Cancel button):

    1. The RequiredFieldValidator Server Control: The RequiredFieldValidator control

    simply checks to see if something was entered into the HTML form element. It is a

    simple validation control, but it is one of the most frequently used. You must have a

    RequiredFieldValidator control for each form element on which you wish to enforce a

    value-required rule.

    2. The CompareValidator Server Control: The CompareValidator control allows you

    to make comparisons between two form elements as well as to compare values

    contained within form elements to constants that you specify. For instance, you can

    specify that a form elements value must be an integer and greater than a specified

    number. You can also state that values must be strings, dates, or other data types that

    are at your disposal.

    3. The RangeValidator Server Control: The RangeValidator control is quite similar to

    that of the CompareValidator control, but it makes sure that the end user value or

    selection provided is between a specified range as opposed to being just greater than

    or less than a specified constant. For an example of this, go back to the text-box

    element that asks for the age of the end user and performs a validation on the value

    provided.

    4. The RegularExpressionValidator Server Control: One exciting control that

    developers like to use is the RegularExpressionValidator control. This control offers a

    lot of flexibility when you apply validation rules to your Web forms. Using the

    RegularExpressionValidator control, you can check a users input based on a pattern

    that you define using a regular expression.

    5. The ValidationSummary Server Control: The ValidationSummary control is not a

    control that performs validations on the content input into your Web forms. Instead,

    this control is the reporting control, which is used by the other validation controls ona page. You can use this validation control to consolidate error reporting for all the

    validation errors that occur on a page instead of leaving this up to each and every

    individual validation control.

    At Design time:

    Step 1: Place the text boxes and a button on the web form to implement the validation on them.

  • 8/12/2019 Dot Net Practical File

    38/41

    38

    Step 2: Now drag the validation control on the web form Validation category from the toolbox.

    Step 3: Set the properties of validation control as follows:

    Control Name Properties of validation control

    RequiredFieldValidator Control to validate. CompareValidator Control to validate.

    Control to compare. RangeValidator Control to validate.

    Maximum value. Minimum value.

    RegularExpressionValidator Control to validate. Validation Expression

    ValidationSummary Gives the list of validation errors.

    Figure: Validation form example

    At Run time: Debug the Web Form, Now when you press the button the validation will check

    the data inputted is valid or not. If any violation of validation is there then it shows the error.

  • 8/12/2019 Dot Net Practical File

    39/41

    39

    AIM 11: To study the ADO connectivity in .net

    Microsoft tried reinventing data access again with OLE DB (OLE for Databases). OLE DB tieddatabase development directly to Microsoft's Component Object Model (COM). OLE DB is a set

    of COM interfaces that exposes a consumer/provider model of accessing data throughout anenterprise. OLE DB makes no distinction as to whether the data is in a desktop database (like

    Access), an enterprise database (like SQL Server or Oracle), or a non-database source (like an

    Excel spreadsheet). If developers wanted to expose their data to OLE DB they needed to develop

    an OLE DB provider. Unfortunately, development of OLE DB providers proved to be difficultfor all but the most talented C++ developers. Developing data consumers in OLE DB was much

    simpler, but tied developers directly to Visual C++, therefore losing any language independence.

    In the most recent past, Microsoft developed ActiveX Data Objects (ADO) as a COM wrapper

    around OLE DB. ADO was developed specifically to make OLE DB easier to use. Soon after the

    release of ADO, the Internet revolution exploded. Developers craved an easy-to-use API to maketheir Web sites and Web applications database driven. ADO's script ability fit perfectly into

    Microsoft's Internet Information Server (IIS) and Active Server Pages (ASPs). ADO soon

    became the lingua franca of Internet Web sites. For small Web sites, ADO shined; it was easy to

    understand and simple to code.

    ADO.NET is a set of .NET classes that allow for the connection and manipulation of data. .NETclasses are separated into namespaces to help segment their specific functionality. In ADO.NET,

    namespaces provide segregation between different parts of the managed provider model.

    ADO.NET Data Structures

    ADO.NET supports three different ways of accessing database information directly: Commands,Data Readers, and Data Sets.

    Command classes (SqlCommand for the SQL Managed Provider and OleDbCommand for theOLE DB Managed Provider) can be used directly to retrieve results from database queries.

    Command classes always support the IDbCommand interface, which can get a scalar result (the

    first column of the first row of a result set) or out parameters of a stored procedure. This sort ofdata is retrieved using IDbCommand.ExecuteScalar() and IDbCommand.ExecuteNonQuery().

    DataReaders (SqlDataReader and OleDbDataReader) are classes that provide something similar

    to ADO's Recordset using a forward-only cursor. In ADO, we need to be careful and make sure

    we call MoveNext() and check for the end-of-record indicator. The DataReader uses a less error-prone system that just requires that you read the current record into memory and check for the

    end-of-record indicator in one step. For cases where you will need to simply get a query andspew out the results, the DataReader is the perfect vehicle. In fact, Microsoft uses DataReaders

    within the managed providers' DataAdapters to fill DataSet.

    The DataSetlooks much like an OLE DB RowSet or an ADO Recordset. The DataSet, however,

    is much more than that. It is a complex data structure that allows for an in-memory

  • 8/12/2019 Dot Net Practical File

    40/41

    40

    representation of almost any relational model. The DataSet holds a collection of tables that can

    have optional DataRelations, Constraints, or even ForeignKeyConstraints.

    Example:

    At Design time:

    Place Gridview and access DataSource on the web form. Click on the top right corner of the DataSource, and click on configure data source. Follow the wizard and chose the relevant data from the table. Now click on the top right corner on the Gridview and click on Choose data source and

    select the data source configured in the second step.

    Now run the program by pressing theF5key.

    (b) To show data in DetailVi ew :

    using System.Data;

    using System.Configuration;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Data.SqlClient;

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

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    if(!Page.IsPostBack)

    {

  • 8/12/2019 Dot Net Practical File

    41/41

    bind();

    }

    }

    private void bind()

    {

    SqlDataAdapter adp = new SqlDataAdapter("select * from products",

    ConfigurationManager.ConnectionStrings["cn"].ConnectionString);

    DataSet ds = new DataSet();

    adp.Fill(ds);

    DetailsView1.DataSource=ds;

    DetailsView1.DataBind();

    }