Re : Simple databinding code

Posts   
 
    
Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 17-Jan-2008 13:38:48   

Using the generated code what is the simplest fragment of code, in code behind file, required to bind to an asp.gridview control. i.e. without using or instantiating any datasource control.

I am thinking in terms of binding a generated collection class or an entity class. Is this possible?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Jan-2008 14:59:21   

If you don't want to use LLBLGenProDataSource.

Then all you have to do is (assuming that the entityCollection is fetched beforehand):

myGridView.DataSource = myEntityCollection;
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 17-Jan-2008 21:16:45   
  • call DataBind() wink
Frans Bouma | Lead developer LLBLGen Pro
Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 21-Jan-2008 06:00:08   

Sorry I still cant get it to work. I realise it is a simple thing but nothing is displayed in the grid. To repeat, I want to display say data from the categories table (Northwind db) by binding to the gridview control. I am using LLBLGen Pro 2.5 demo. I am using self servicing and two class template to generate the code.

I am also looking to edit,delete and add rows to the categories table all in code. i.e.not using datasource control.

I would appreciate some sample simple code.

I have attempted what you have suggested, no records are displayed and no errors are produced either.

Thank you.

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 21-Jan-2008 09:16:10   

Can you post the ASPX and Codebehind files?

Did you debug the code and test that the databind code was actually hit?

Cheers, Gab

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Jan-2008 09:28:02   

In addition to what Gab has said, please examine the generated SQL query if it exists. Consult the LLBLGen Pro manual's section "Using the generated code -> Troubleshooting and debugging"

Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 22-Jan-2008 05:49:43   

Can you please write down the 2 or 3 lines of code you use to bind to the grid. e.g. you set the datasource and then call the databind method. Please give me the lines of code before the two lines of code above. I do not have access to a development machine right now. Once I am back home will send you the code behind code etc., if necessary. Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Jan-2008 09:52:12   

The collection should be fetched first.

myCollection.GetMulti(); // pass a filter if you wish myGrid.DataSource = myCollection; myGrid.DataBind();

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 22-Jan-2008 10:26:01   

When you get access to the development machine just do the following:

Go in debug, Set a breakpoint on:

  • myGrid.DataSource = myCollection;

Verify if myCollection.Count > 0

If count is > 0 and still nothing is visible, remove your current Grid, add a new one, don't define columns and set AutoColumns to true. Then bind the datasource to the new grid. That should work.

Cheers, Gab

Krish
User
Posts: 91
Joined: 02-Jan-2008
# Posted on: 25-Jan-2008 09:41:11   

The following code fragment got it working :

CategoriesCollection catCol = new CategoriesCollection(); catCol.GetMulti(null); GridView1.DataSource = catCol; GridView1.DataBind();

Also the following lines in the web.config file : <appSettings> <add key="Main.ConnectionString" value="data source=DEV-VISTA-10;initial catalog=Northwind;integrated security=SSPI;persist security info=False;packet size=4096"/> </appSettings>

Thank you for the help and prompt replies.