ASP.NET and GridViews

Soldato
Joined
18 Oct 2002
Posts
9,158
Hi All,

I've been playing with asp.net and in particular gridviews. I am however wanting to do something which I can not seem to get to work.

I want to define the datasource of the gridview as an objectdatasource (I'm using a vs.net data set and table adapters), now, I can do this fine through the gridviews little wizzard, however this places all the code in the .aspx file. What I want is for all the declaration of the objectdatasource stuff to be done in the pages .aspx.vb file, or even better in a seperate class.

Is there anyway to do this?

Regards,

James :)
 
Create a new dataset by right clicking on the project then selecting add->add new item->dataset. This should take you through the dataset creation wizard allowing you to configure the dataadapters etc. All the code for this will be placed in it's own class. Then when you add a new gridview to a page in design mode you can select your datasource using the inline design support for the gridview control.

You can find a very good step by step tutorial on doing just this here

EDIT: This may also help... Link
 
Last edited:
The problem is if you create the datasource programmatically (in the code-behind file) you won't be able to reference it directly in your declarative gridview (.aspx file). Best to either both create them programmatically or both declaratively.
 
Back
Top Bottom