Opt In (Do Not Edit Here)

Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Mar 11, 2012

Creating HTMLTable Dynamically

          The blog is intended to demonstrate the use of some HTMLControls for dynamically generating the HTMLTable on webpage using some piece of code.
          Required Namespace: System.Web.UI.HtmlControls

Controls used:
1.    Two Textboxes (txtRow & txtCol)
2.    One Button (btnClick)
3.    One Blank Table (htmlTable1)

Step 1: Accept the no. of Rows and Columns from User.
            int row = Convert.ToInt32(txtrow.Text);     // No. of Rows
            int col = Convert.ToInt32(txtcol.Text);     // No. of Columns
 Listing 1

Step 2: Now, Initialize the new TableRow & TableCell to add Data into Table.
            for (int i = 0; i < row; i++)
                  HtmlTableRow rows = new HtmlTableRow();         //a new Row
                  for (int j = 0; j < col; j++)
                        HtmlTableCell cell = new HtmlTableCell(); //a new Cell
Listing 2

Step 3: You can put any data into Cell, also can make some FORMATTING for good looks, and then add this cell to the row element…
                   cell.InnerHtml = i + "," + j;               //Insert Data into Cell
            cell.Align = "Center";
            cell.BorderColor = "Gray";
            rows.Cells.Add(cell);                       //Attach Cell with Row
Listing 3

Step 4: Now, simply insert this row element into htmlTable1 to display that row on the screen.

               htmlTable1.Rows.Add(rows);                      //Attach Row with Table
Listing 4

Step 5: Now execute the web application and see the result.

Intended Result:

Figure 1


          In this piece of writing, we see how to generate the HTML table with user accepted rows and columns. For writing the code here I used the C# and ASP.NET.

May 12, 2011

FileSystemObject - Drive Object

1.     First we have to declare four variables.

     Dim FSO, Drive, AllDrive, type

2.    Now create an instance of FileSystemObject and access all the available drives in computer.
      FSO = Server.CreateObject("Scripting.FileSystemObject")

     AllDrive = FSO.Drives

3.    Now display the Information for each drive

     Response.Write("Demo - Drive Object ")
For Each Drive In AllDrive

        Response.Write("Drive Letter :"+ Drive.DriveLetter()+"")
Response.Write("Path :  " + Drive.Path())
Response.Write("IsReady : " + Drive.IsReady().ToString)

   If Drive.IsReady Then   'To Retrieve the Type of Drive
      Response.Write("Drive Type : ")
      Select Case Drive.DriveType()
      'Property DriveType() Returns a Value indicating
      'the Type of a Specified Srive.
          Case 0 : type = "Unknown"
          Case 1 : type = "Removable"
          Case 2 : type = "Fixed"
          Case 3 : type = "Network"
          Case 4 : type = "CD-ROM"
          Case 5 : type = "RAM Disk"
      End Select

      'To Retrieve the Name of the Drive
      Response.Write("Volume Name : " + Drive.VolumeName)

      'To Retrieve the Type of File System
      Response.Write("File System : " + Drive.FileSystem)

      'To Retrieve the Total of the Specified Drive in GigaByte(GB)
      'The Division by(1024*1024*1024) to the Specified Property
      'is Done to get the Size of specified Drive in GigaByte
      Response.Write("Total Size : " + (Drive.TotalSize() / (1024 * 1024 * 1024)).ToString + " GigaByte")

      'The value returned by the FreeSpace property is typically         'the same as that returned the AvailableSpace property.              'Differences may occur between the two for
      'computer systems that support quotas.
      Response.Write("Free Space : " + (Drive.FreeSpace() /(1024 * 1024 * 1024)).ToString + " GigaByte")
      Response.Write("Available Space : "+(Drive.AvailableSpace() / (1024 * 1024 * 1024)).ToString + " GigaByte")

       'To Retrieve the Serial Number(in Hex) of 
       'the Specified Drive
        Response.Write("Drive Serial Number : " + Hex(Drive.SerialNumber))
    End If

4.    The Output will be as follows…..

Objects and Collections of FileSystemObject


          Contains methods and properties that allow you to create, delete, gain information about, and generally manipulate drives, folders, and files. Many of the methods associated with this object duplicate those in other FSO objects; they are provided for convenience.

          Contains methods and properties that allow you to gather information about a drive attached to the system, such as its share name and how much room is available. Note that a "drive" isn't necessarily a hard disk, but can be a CD-ROM drive, a RAM disk, and so forth. A drive doesn't need to be physically attached to the system; it can also be logically connected through a network.

          Contains methods and properties that allow you to create, delete, or move a file. Also allows you to query the system for a file name, path, and various other properties.

          Contains methods and properties that allow you to create, delete, or move folders. Also allows you to query the system for folder names, paths, and various other properties.

          Allows you to read and write text files.


          Provides a list of the drives attached to the system, either physically or logically. The Drives collection includes all drives, regardless of type. Removable-media drives need not have media inserted for them to appear in this collection.

          Provides a list of all files contained within a folder.

          Provides a list of all the folders within a Folder.


FileSystemObject Basics

          When writing scripts for Active Server Pages, the Windows Script Host, or other applications where scripting can be used, it's often important to add, move, change, create, or delete folders (directories) and files on the Web server. It may also be necessary to get information about and manipulate drives attached to the Web server.
     Scripting allows to process drives, folders, and files using the FileSystemObject (FSO) object model.

FileSystemObject (FSO) Object Model 

          The FileSystemObject (FSO) object model allows using the familiar object.method syntax with a rich set of properties, methods, and events to process folders and files.
This object-based tool can be with: 

  • HTML to create Web pages 
  • Windows Scripting Host to create batch files for Microsoft Windows 
  • Script Control to provide a scripting capability to applications developed in other languages


  • The FSO object model gives server-side applications the ability to create, alter, move, and delete folders, or to detect, and also to get the information about folders, such as their names, the date they were created or last modified, and so forth.

o   The FSO object model makes easy to process the files (such as create files, insert and change the data, and output (read) the data).

  • Also supports text file creation and manipulation through the TextStream object.


          Because use of the FSO on the client side raises serious security issues about providing potentially unwelcome access to a client's local file system, this documentation assumes use of the FSO object model to create scripts executed by Internet Web pages on the server side. Since the server side is used, the Internet Explorer default security settings do not allow client-side use of the FileSystemObject object. Overriding those defaults could subject a local computer to unwelcome access to the file system, which could result in total destruction of the file system's integrity, causing loss of data, or worse.

Apr 22, 2011

DataList Control in ASP.NET using Wizard

Programming Level : Beginner
Programming Environment : Visual Studio 2008
          Language : Visual C# 2008



In this Article, we are taking Overview of DataList Control in ASP.NET.

  • The DataList Web server control displays rows of database information in a customizable format. The format for displaying the data is defined in templates
  • The DataList control is useful for data in any repeating structure, such as a table.
  • The DataList control can display rows in different layouts, such as ordering them in columns or rows.
  • The DataList control renders items in a list using HTML table elements.

Now Follow the Below Steps to Use DataList Control Through Wizard..........

  1. Create new Website in Visual Studio.
File à New Web Site … (‘New Web Site’ Dialog Box will appear.)
  1. Set the Language to “Visual C#” or “Visual Basic” in ‘New Web Site’ Dialog Box.
  2. Now, Open “Default.aspx” file appeared in Solution Explorer.

  1. Drag the DataList Control from Tool Box onto the Default.aspx (Design).

Figure 1: Drag the DataList Control to the Default.aspx File

  1. Now, select the <New Data Source> option from DataList Taks.

Figure 2: Selecting Data Source

  1. Select Data Source Type and Specify the ID for it. Then click OK Button.

  1. Choose Data Connection to connect with Database Then click Next Button.

  1. Now, select the Table Name and Column(s) to be display on DataList, Then Click Next Button.

  1. If you want to verify the Select Statement, Click Test Query Button.

After Click Finish Button, you’ll see the changes in DataList Control as follows

10. Now, if you want to change the Display color of DataList, click the Auto Format… option present in the DataList Tasks and change the Color.(Optional)

  1. We can also Use the Templates provided by DataList Control, templates are as follows (Optional) :-

Note: Default Template for DataList is ItemTemplate

12. For now I have formatted DataList as Follows:-

  1. Now, Run the Project by pressing function key
F5 (Run with Debugging)
Ctrl+F5 ( Run without Debugging)

  1. Result will be displayed in Default Web Browser as follows:-

If you want to avoid the selection of Data Source and formatting the DataList Items through Wizard, then SKIP the Steps 5 to 12.
Instead of Performing Steps 5 to 12, you can also simply type the code for different templates provided by DataList Control into the Source Section of the Default.aspx.

All Rights Reserved. 2014 Copyright SIMPLITONA

Powered By Blogger | Published By Gooyaabi Templates Designed By : BloggerMotion