ASP.Net DataGrid

Posts   
 
    
ZingBang
User
Posts: 5
Joined: 14-May-2005
# Posted on: 14-May-2005 20:56:09   

I bound a .Net DataGrid with an EntityCollection from the Toolbox (SelfServicing). When I loaded the datasource at runtime everything worked fine. When I use the Property Builder on the DataGrid and Uncheck Create Columns Automatically at Runtime and Select only specific columns to display, the same code to load the data does not work. Quickwatch on the object still shows that it's loaded but the binding fails without exception.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 16-May-2005 10:59:58   

ZingBang wrote:

I bound a .Net DataGrid with an EntityCollection from the Toolbox (SelfServicing). When I loaded the datasource at runtime everything worked fine. When I use the Property Builder on the DataGrid and Uncheck Create Columns Automatically at Runtime and Select only specific columns to display, the same code to load the data does not work. Quickwatch on the object still shows that it's loaded but the binding fails without exception.

Do you bind a child collection to the grid? Like: you bind a CustomerCollection, but the DataMember is set to 'Orders' ? This is important for the table style name.

Frans Bouma | Lead developer LLBLGen Pro
gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 19-May-2005 19:16:02   

I wanted to post a question, but I guess this is relevant for me too. I would like to bind the following to a column:

ticketsCollection.Items[0].Contacts.FullName

I thought this would work:

Contacts.FullName

But it doesn't. I guess it's simple but can't find it in manual or on the forum with my search keys.

Thanks in advance for any help,

Greets, Gab

ZingBang
User
Posts: 5
Joined: 14-May-2005
# Posted on: 20-May-2005 04:02:56   

No. I bind the main collection. This is what I am doing.


MemberCollection m = new MemberCollection; m.GetMulti(null);

DataGrid1.Datasource = m;

DataGrid1.Databind();

Let's presume this table

MEMBER -id -name -phone -zip -username -password

If I use the property builder on a Datagrid which is being bound to a member collection at design time, the above code does not work (Reference original message). Let's say I only wanted to show name and phone in the datagrid, I would use the property builder to define which columns to show.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-May-2005 12:16:30   

gabrielk wrote:

I wanted to post a question, but I guess this is relevant for me too. I would like to bind the following to a column:

ticketsCollection.Items[0].Contacts.FullName

I thought this would work:

Contacts.FullName

But it doesn't. I guess it's simple but can't find it in manual or on the forum with my search keys.

Thanks in advance for any help,

Greets, Gab

Set datamember of the grid to 'Contacts' and specify 'TicketsCollection' for the mapping name of the tablestyle, otherwise it won't work.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-May-2005 12:17:16   

ZingBang wrote:

No. I bind the main collection. This is what I am doing.


MemberCollection m = new MemberCollection; m.GetMulti(null);

DataGrid1.Datasource = m;

DataGrid1.Databind();

Let's presume this table

MEMBER -id -name -phone -zip -username -password

If I use the property builder on a Datagrid which is being bound to a member collection at design time, the above code does not work (Reference original message). Let's say I only wanted to show name and phone in the datagrid, I would use the property builder to define which columns to show.

Specify 'MemberCollection' for the mapping name in the table style. Does that work in your case then?

Frans Bouma | Lead developer LLBLGen Pro
ZingBang
User
Posts: 5
Joined: 14-May-2005
# Posted on: 20-May-2005 14:42:33   

That didn't work. Presuming what I was doing was right (Shown Below).

DataGrid1.Style.Add("Mapping Name","MemberCollection");

BTW -- When I compile an ASP.Net project that has a design view open of a web controls the llbl collection that I added from the toolbar disappears.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-May-2005 15:05:18   

I'll see if I can reproduce this. Though I'll only test this with native .NET grids.

Frans Bouma | Lead developer LLBLGen Pro
ZingBang
User
Posts: 5
Joined: 14-May-2005
# Posted on: 20-May-2005 18:35:18   

I am using native .Net grids.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-May-2005 19:15:53   

I've done: - create a new webform. - dragged a datagrid onto the webform. - added a selfservicing collection to the toolbox (ThreadCollection, of this forum) - I dragged the collection onto the form, I got 'threadCollection1'. - I set the grid's datasource property to 'threadCollection1'. All columns show up. - I clicked on the [...] button next to 'Columns'. This opens the property builder. - I de-checked 'create columns automatically at runtime' - Then I added 2 columns from the 'Available columnlist' to 'selected columns' - I clicked OK. THe grid in the forum has now two columns.

The page_load routine:


private void Page_Load(object sender, System.EventArgs e)
{
    // Put user code to initialize the page here
    threadCollection1.GetMulti(null);
    DataGrid1.DataSource = threadCollection1;
    DataGrid1.DataBind();
}

It works ok, I get 2 columns instead of 12 or so.

So, I think the main issue is that 'create columns automatically at runtime' is checked / set to true in your case I think.

As your collection dissapears when you compile, I'm not sure to which dll you've browsed when you added the collections to the toolbox. Perhaps you should use website\bin folder instead?

Frans Bouma | Lead developer LLBLGen Pro
ZingBang
User
Posts: 5
Joined: 14-May-2005
# Posted on: 21-May-2005 21:14:06   

I retried it in a different solution and everything worked fine.

Thanks.