views:

1239

answers:

1

I have a FormView (bound to an ObjectDataSource) that contains a CheckBoxList that I'd like to bind to a single property of the underlying object that is an Enum with the FlagsAttribute applied to it. Binding to the SelectedValue property always gives me just the FIRST selected value from the list as the property's value. Anyone know how to get around this without overriding the Inserting or Updating methods and manually getting the values of the checkbox list and stuffing it into the parameters of the datasource? Sample code below of what I'm trying to do...

<asp:FormView runat="server" ID="MyFormView" DataSourceID="MyDataSource">
   <InsertItemTempate>
      <asp:CheckBoxList runat="server" ID="MyCbl" SelectedValue='<%# Bind("MyProperty") %>'>
         <asp:ListItem Text="Choice 1" Value="ChoiceOne"></asp:ListItem>
         <asp:ListItem Text="Choice 2" Value="ChoiceTwo"></asp:ListItem>
      </asp:CheckBoxList>
   </InsertItemTemplate>
</asp:FormView>
<asp:ObjectDataSource runat="server" ID="MyDataSource" TypeName="MyClass" ...></asp:ObjectDataSource>

behind the scenes, my object is declared like this...

public class MyClass
{
   public MyEnum MyProperty { get; set; }
}

[Flags()]
public Enum MyEnum
{
   ChoiceOne = 1,
   ChoiceTwo = 2
}
+1  A: 

You will have to iterate through the Items collections and build up the enum values from there.

A search on Google for FlaggedEnumTypeConverter should also be helpful.

leppie
yeah, that's what I've always done - just thought maybe there was a better way out there that I didn't know about...
Scott Ivey