ASP.NET 2.0 DataBinding with object oriented business classes

G

Guest

Hi ASP.NET 2.0 Professionals,

I've got a question concerning the new ASP.NET 2.0 DataBinding with object
oriented business classes:

Example:

There are two business classes in my domain model:

public class Language
{
public int ID;
public string Name;
}

public class User
{
public int ID;
public string Firstname;
public string Lastname;
public Language UserLanguage;
}

Now I want to bind objects of the two classes to the data controls of a
FormView control.

I am using two ObjectDataSource Controls "odsUser" to retrieve a User object
(linked to the FormView) and "odsLanguages"
to fill a DropDownList with all possible Languages.

<asp:ObjectDataSource ID="odsUser" runat="server" SelectMethod="Get"
TypeName="DomainModel.Users.UserStorage">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="id" QueryStringField="id"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

<asp:ObjectDataSource ID="odsLanguages" runat="server" SelectMethod="GetAll"
TypeName="DomainModel.Common.LanguageStorage">
</asp:ObjectDataSource>


The question is:

How do I bind the current Language of a User object to the DropDownList?

I tried this but the compiler doesn't like it:

<asp:DropDownList ID="ddlDropDownList" DataSourceID="odsLanguages"
runat="server" DataTextField="Name" DataValueField="ID" SelectedValue='<%#
Bind("Language.ID") %>' ></asp:DropDownList>

The Expression Bind("Language.ID") is not allowed here.


I think this is a typical data binding problem of any enterprise application
with an object oriented domain model.


Thanks in advance

- Ulrich Schumacher
 
I

intrader

Hi ASP.NET 2.0 Professionals,

I've got a question concerning the new ASP.NET 2.0 DataBinding with object
oriented business classes:

Example:

There are two business classes in my domain model:

public class Language
{
public int ID;
public string Name;
}

public class User
{
public int ID;
public string Firstname;
public string Lastname;
public Language UserLanguage;
}

Now I want to bind objects of the two classes to the data controls of a
FormView control.

I am using two ObjectDataSource Controls "odsUser" to retrieve a User object
(linked to the FormView) and "odsLanguages"
to fill a DropDownList with all possible Languages.

<asp:ObjectDataSource ID="odsUser" runat="server" SelectMethod="Get"
TypeName="DomainModel.Users.UserStorage">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="id" QueryStringField="id"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

<asp:ObjectDataSource ID="odsLanguages" runat="server" SelectMethod="GetAll"
TypeName="DomainModel.Common.LanguageStorage">
</asp:ObjectDataSource>


The question is:

How do I bind the current Language of a User object to the DropDownList?

I tried this but the compiler doesn't like it:

<asp:DropDownList ID="ddlDropDownList" DataSourceID="odsLanguages"
runat="server" DataTextField="Name" DataValueField="ID" SelectedValue='<%#
Bind("Language.ID") %>' ></asp:DropDownList>

The Expression Bind("Language.ID") is not allowed here.


I think this is a typical data binding problem of any enterprise application
with an object oriented domain model.


Thanks in advance

- Ulrich Schumacher
Your classes must implement interfaces as follows:
Simple objects must implement the IEditableObject interface,
Collection objects must implement IBindingList intervace.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top