how to fill container.dataitem in asp.net

Posts   
 
    
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 05-Jan-2004 20:59:34   

When you have a checkbox template in a datagrid how do I bind the value I want showing up?

Below is how I do it with a datatable as the datasource. I am setting datasource = dealerscollection.

What do I put in place of "active" below to make this work?

<asp:checkbox id=active runat="server" Enabled="true" text="Activate" checked='<%#container.DataItem("active")%>'>

The error I am getting is:

No default member found for type 'DealerEntity'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMemberException: No default member found for type 'DealerEntity'.

Source Error:

Line 111: <asp:TemplateColumn SortExpression="active" HeaderText="Active"> Line 112: <ItemTemplate> Line 113: <asp:checkbox id=active runat="server" Enabled="true" text="Activate" checked='<%#container.DataItem("active")%>'> Line 114: </asp:checkbox> Line 115: </ItemTemplate>

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 05-Jan-2004 21:29:34   

That will take some casting simple_smile

<asp:checkbox id=active runat="server" Enabled="true" text="Activate" checked='<%# CType(container.DataItem, DealerEntity).Active%>'>

Does that work? You have to cast the container.DataItem to the entity, then reference the property. You also have to reference the assembly which contains DealerEntity in the page header of course.

Frans Bouma | Lead developer LLBLGen Pro
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 05-Jan-2004 22:10:54   

Yes, that works and makes perfect sense, but you don't even have to cast to get it to work because vb.net actually will convert for you.

I sure wish my brain would have thought of that, but I didn't really know much about the container.datatitem.

Thanks,

Terry