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:
<aspropDownList ID="ddlDropDownList" DataSourceID="odsLanguages"
runat="server" DataTextField="Name" DataValueField="ID" SelectedValue='<%#
Bind("Language.ID") %>' ></aspropDownList>
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'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:
<aspropDownList ID="ddlDropDownList" DataSourceID="odsLanguages"
runat="server" DataTextField="Name" DataValueField="ID" SelectedValue='<%#
Bind("Language.ID") %>' ></aspropDownList>
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