Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 12th, 2006, 01:54 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Gridview manual databinding through code

Hi there,

Im new to vs.net 2005.ive used 2003.can u tell me how to manuallly bind the gridview in asp.net 2.0 .i did search over the net but couldnt get any answers.and if possible if u no tell me the best book to read thru.

Reply With Quote
  #2 (permalink)  
Old December 12th, 2006, 03:25 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Exactly as you did in .NET 1.x.

In Code Behind, set its DataSource (not DataSourceID) to a valid data source and then call DataBind().

You are aware of all the new *DataSOurce controls, aren't you?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old December 12th, 2006, 05:00 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Imaar,
i.e.
GridView1.DataSource=SqlDataSource.SelectCommand
GridView1.DataBind()

or is it
GridView1.DataSource=SqlDataSource
GridView1.DataBind()

i tried it, but its not working.and how do you set the datakeyname thru code.if u dont mind just write the code.

Reply With Quote
  #4 (permalink)  
Old December 12th, 2006, 01:18 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Depending on where your data comes from, you can do different things.

For example, if you have a data source like a DataTable or, an Array, or a collection or whatever, you can do this:

GridView1.DataSource = myDataTable
GridView1.DataBind()

Replace myDataTable with your object.

Alternatively, if you want to use the data from a *DataSource control, you can do this:

GridView1.DataSourceID = mySqlDataSource.ID
GridView1.DataBind()

or

GridView1.DataSourceID = "myDataSource"
GridView1.DataBind()

This sets the DataSourceID property of the GridView to the ID of the data source instead of assigning its DataSource property.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding DropDownList in gridview template hughworm BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 October 15th, 2008 11:16 AM
Manual Submit Digon Classic ASP Basics 2 December 28th, 2005 08:24 PM
Crystal manual crosstab Eric Butterfield Crystal Reports 1 February 18th, 2005 06:42 PM
Manual Copy-Of aberglas XSLT 1 February 17th, 2005 05:40 AM



All times are GMT -4. The time now is 10:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.