A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Basics of using DataGridThis tutorial introduces you to the DataGrid control. It tells you about the BoundColumn and shows an example of how to use it. |
On Monday, September 13th 2004 at 05:24 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 3.7 with 60 votes) |
||||
|
The DataGrid control, similar to the DataList control but with more features, bounds data and displays it in a grid. We shall begin with just displaying the records from the database MyDB (which we used in several tutorials, here at Geekpedia and which was created in the tutorial named 'Connecting to a SQL database from ASP .NET I'). Anyway, for setting up fast a connection to the SQL database from the ASP .NET Web Application use the following code inside WebForm1.aspx.cs: Inside the public class named WebForm1:
Inside InitializeComponent() - after you expand the region:
On the web form (design mode of WebForm1.aspx) drag a DataGrid control: ![]() Now go to the C# code file (WebForm1.aspx.cs) and inside Page_Load() use the following code:
Here we simply bind the control to the database, and if you compile now you'll see the result in the browser: ![]() The bind was successful. The title of the columns in the DataGrid is the actual name of the columns inside the database (Title and URL). Yet we didn't used any of the features of the DataGrid, and that's what we're going to do next. DataGrid columnsThe BoundColumn BoundColumn is the column that displays the records inside a DataGrid. This is the default column type. You don't have to specify any BoundColumns to display the columns inside the database as they are generated automatically. But if you do specify the columns, you need to set an attribute for the <asp:DataGrid> tag that sets the auto generation of columns to false. Let's do this - go into the HTML code of WebForm1.aspx and inside the form tag of Form1 use the following code:
First you can notice the attribute called AutoGenerateColumns which is set to False, that's because we want to create our own columns. Then, inside the <Columns> tag we create two BoundColumns and we specify to each of them, the DataField (which is actually the column name from the database) and HeaderText - the text which appears above the column. Here's the result in the browser: |
|||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||||
|
|||||
Current CommentsVery Good Tutorial.
It helped me much.
Thx @ Andrei Pociu
Thanks, your tutorial was very helpful.
thanks alot!
Thanks, your tutorial is good .
excellent
Can you tell me how to insert chechkbox in DataGrid
it was fantastic......explained everything in a simple way...thanks a lot......shall i ask the author one thing....its not related to this topic....an asp application design have two parts...one html view and one design view...should i learn html for creating good programs in asp.net??????if i should learn what are topics that i should learn...i expect your kind reply...
<b>eeffe</b>
very nice but now a days we are not using this pointer in Asp.net
thanks i am learning asp.net, and found very good help related to grid.
Thanks for explaining the concepts so clearly...
Thanks for explaining the concepts so clearly...
Thanks
Thanks for sharing.. Easily understood for beginners...
Thanks for sharing.. Easily understood for beginners...
Thanks for sharing.. Easily understood for beginners...
Thanks for sharing.. Easily understood for beginners...
Thanks for sharing.. Easily understood for beginners...
Thanks for sharing.. Easily understood for beginners...
Cheers.
I've been using entity models to handle the SQL connections but the rest helped muchly.
Related Tutorials
Related Source Code
ASP.NET Job Search