Geekpedia Programming Tutorials






How to bind a DataGrid to an array

It simply shows how to bind a DataGrid to an array using C# code.

On Sunday, September 5th 2004 at 07:52 AM
By Andrei Pociu (View Profile)
***--   (Rated 2.8 with 18 votes)
Contextual Ads
More ASP.NET Resources
Advertisement
This tutorial provides a simple code on how to bind a DataGrid to an array.



Start a new ASP .NET Web Application and on the Web Form drag a DataGrid:








Now go into the code of the ASP .NET Web Application (WebForm1.aspx.cs) and replace PageLoad() with this one:





private void Page_Load(object sender, System.EventArgs e)

{

   // The array

   string[] urls =

   {

   "http://www.geekpedia.com",

   "http://msdn.microsoft.com",

   "http://www.codeproject.com"

   };

// Set the DataSource to the array

DataGrid1.DataSource = urls;

// And bind

DataGrid1.DataBind();

}



You can now compile and watch the result:



Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by Eric on Thursday, September 23rd 2004 at 12:26 AM

Thanks - this is what I was looking for!

by eric dr neba on Saturday, September 25th 2004 at 12:11 PM

i believe too and thanks for continued support

by Santosh V. Marri on Tuesday, December 28th 2004 at 01:53 AM

Excellent for the learner. I have solved my problem just following the sequence of steps to configure IIS for .Net

Thanks,

by jak on Tuesday, February 8th 2005 at 04:32 PM

Thanks, I can now prepare my own tax!!

by ajay patil on Wednesday, March 9th 2005 at 08:22 AM

Thanks. but how to bind datagrid to two dimensional array.

Thanks in advance

by Ramesh on Wednesday, October 19th 2005 at 07:26 AM

Thanks. but how to bind datagrid to two dimensional array.and how to change the header

Thanks in advance

by Andrei Pociu on Wednesday, October 19th 2005 at 01:14 PM

How to change the header? Using the HeaderText attribute of the &lt;asp:BoundColumn&gt; tag as seen in this tutorial: <a href="http://www.geekpedia.com/tutorial97_Basics-of-using-DataGrid.html">Basics of using DataGrid</a>.

by necky on Tuesday, December 27th 2005 at 05:32 AM

Hi,
can anyone tell me how to add an array to the chat room.... or a code to allowed more than one person to chat from different location

by Kelly Dirks on Wednesday, February 15th 2006 at 12:49 PM

How do you do this with a datagrid on a Windows form? When I do it I get the lenght of the string displayed in the datagrid, not the actual string text.

by NewCoder on Friday, March 17th 2006 at 02:34 AM

How do you do this with a datagrid on a Windows form? When I do it I get the lenght of the string displayed in the datagrid, not the actual string text.

by Vishal on Monday, July 23rd 2007 at 05:14 PM

having trouble implementing with jagged arrays....

by Tammie on Tuesday, September 4th 2007 at 08:16 PM

Curious about jagged arrays also. How can you bind to an array of arrays or two-dimentional arrays? Whats does the aspx code look like? How do we access fields using templates?


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs ASP.NET Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons