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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top