Problems with DetailsView

Discussion in 'ASP .Net' started by Giulio Petrucci, Aug 3, 2009.

  1. 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
    --
     
    Giulio Petrucci, Aug 3, 2009
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.