Problems with DetailsView

  • Thread starter Giulio Petrucci
  • Start date
G

Giulio Petrucci

Hi there,

I have a Foo class with a property FooType, which is an enum with three
values: X,Y,Z.
At the UI level, the Foo instance editing is performed by a details
view. So I prepared a Dto like this:

class FooDto
{
FooDto()
{
FooDtoType = FooType.X.ToString(); //default;
}

string FooDtoType { get; set; }
IEnumerable<string> FooTypeList
{
get
{
return Enum.GetNames(typeof(FooType));
}
}
}

and my DetailsView will be something like:

<asp:DetailsView ID="fooDetailsView" runat="server">
<asp:TemplateField HeaderText="FooType" InsertVisible="true">
<EditItemTemplate>
<asp:DropDownList ID="TypeList" runat="server"
DataSource='<%# Eval("FooTypeList") %>'
HeaderText="Tipo" SelectedValue='<%#
Bind("FooDtoType")%>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="TypeList" runat="server"
DataSource='<%# Eval("FooTypeList") %>'
HeaderText="Tipo" SelectedValue='<%#
Bind("FooDtoType")%>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Literal ID="FooType" runat="server" Text='<%#
Eval("FooDtoType") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</asp:DetailsView>

If I try to edit an existing FooDto (pushing the DetailsView control in
edit mode) everything works fine and in my field I can see a drop down
list filled with all the enum values. If I try to add a new FooDto
(pushing my DetailsView in insert mode) the drop down list is empty
(despite of having boud the control to a new FooDto instance). What's
wrong with my code?

thanks in advance,
Giulio
--
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top