DataGrid Programming Made Easy
page 1 of 1
Published: 29 Sep 2003
Unedited - Community Contributed
The DataGrid has paging, sorting, editing, deleting, and adding capabilities, but code has to be written to make them work. My code sample is a solution to this, because it has these sub-routines already made.
by Andrew Mooney
Average Rating: 
Views (Total / Last 10 Days): 7232/ 24

[ Download Code ] | [ Run Sample ]

During my time as a database programmer I have developed many useful tools and this is the latest. The DataGrid has built-in capabilities to page, sort, edit, delete, and add, but code has to be written to make them work. This code sample is a solution to this, because it has page, sort, edit, delete, and add sub-routines already made. Using a DataGrid in one web page to make a DataGrid for another web page, allows for quick and easy creation of web pages that display information from tables in a database.

Using OleDb for connecting to databases adds versatility to this tool by allowing you to use the same code with different database types. The add routine simply adds a blank record to the database and then re-binds the DataGrid. Then the new record is moved to edit mode, where the data for the record can be entered and saved.

Known Limitations:

  1. You must use OLEDB connection strings:
    PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\db\database.mdb;
    PROVIDER=SQLOLEDB; Data Source=(local); Initial Catalog=database;User ID=sa;Password=;
  2. Only tested with Access 2000 and SQL Server 2000.
  3. Does not support all data types, but should work with:
     String ( 129, 130, 200, 201, 202, 203 )
     Numeric ( 2, 3, 4, 5, 6, 17, 20, 131 )
     Date/Time ( 7, 135 )
     Boolean ( 11 )
  4. Each table must have an Identity or AutoNumber field as the single primary key.
  5. Other than the single primary key, non-updateable fields are not supported.
  6. To use Allow Add you must also Check Allow Edit.
  7. If you check Allow Edit you must check at least one column to be edited.
  8. You must select at least one field to be shown.

To use this sample:

  1. Enter an OLEDB Connection String and click Connect.
  2. Select a table from the drop down list and click Get Table Info.
  3. Select whether you want to Allow Edit, Allow Delete, or Allow Add.
  4. Using the checkboxes select which columns should be shown, sorted, and edited on your new page.
  5. Using the checkboxes select which columns should have a multiline textbox in edit mode.
  6. Click Create ASP.NET Page
  7. A textbox will appear containing the code for your new page. Copy and paste the code into your text editor and save with the .aspx extension.

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-28 6:23:43 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search