ASP.NET & Databases Part 4
page 4 of 5
by . .
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22707/ 68

The DataGrid Control


This is probably the most powerful control, it can go from simple to complex. I have already written an article on it but there are a few things that I can show you with it that it didn't cover.

Instead of templates, the DataGrid has types of columns :

  • Bound Columns These allow you to specify how a column is displayed, these are the default ones used by the DataGrid.
  • Button Columns These columns have buttons in them that can be customized.
  • Edit Command Column This allows you to edit items, when clicked it replaced the items with editable fields and several options.
  • Hyperlink Column A column with a hyperlink.
  • Templated Column A custom column.
dg.DataSource = ds.tables("users").DefaultView
End Sub

<asp:DataGrid id="dg" runat="server" />

This is the most simple form of viewing data in a DataGrid, this creates a table with the column names equaling the names in the actual DataTable and the information is just listed in rows, no special formatting or anything.

dg.DataSource = ds.tables("users").DefaultView
End Sub

<asp:DataGrid id="dg" runat="server"


<asp:BoundColumn HeaderText="ID" DataField="ID" />

<asp:templateColumn HeaderText="Name">
      <asp:label id="Name" runat="server" Text='<%
# Container.DataItem("FName") & " " & Container.DataItem("LName") %>' />



This is a bit more complicated, but not as bad as it gets.

  • After a Standard Databinding session we set many properties of the DataGrid (self explanatory ones are left out)
    • GridLines If you want to specify a single way that the gridlines go, do it here.
    • AutoGenerateColumns If this is true it makes the columns up for you, if its false, it relies on your Columns that you set up. If it is true and you have defined columns then it will use both your columns and the Auto Generated ones.
  • Next we start to put in columns.
  • The BoundColumn for the ID Field
  • A Template Column (you can see the template that we're using here (the ItemTemplate)) and we then put a label on it.
  • We close tags.

This is no where NEAR the amount of stuff you can do on DataGrids, and because I like them, look out for an article - Advanced DataGrids.

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

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

©Copyright 1998-2021  |  Page Processed at 2021-12-02 8:45:47 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search