I was wondering if there is a way to use the new model binding in combination with a dropdownlist. When searching on the net, all I found were examples of the DropDownList being used a filter control or e.g. a bound GridView. Let's say however a user would
be able to select a gender (M/F). For this data I would like the user to be able to select the correct gender from a DropDownList. The code below illustrates in general what I am aiming for:
tim_tegenbos...
0 Points
3 Posts
Model Binding to DropDownList
Apr 20, 2012 03:49 PM|LINK
I was wondering if there is a way to use the new model binding in combination with a dropdownlist. When searching on the net, all I found were examples of the DropDownList being used a filter control or e.g. a bound GridView. Let's say however a user would be able to select a gender (M/F). For this data I would like the user to be able to select the correct gender from a DropDownList. The code below illustrates in general what I am aiming for:
<asp:FormView runat="server" ID="frmClubMembers" DataKeyNames="MemberId" ItemType="Domain.Member" DefaultMode="ReadOnly" InsertMethod="InsertMember" UpdateMethod="UpdateMember" SelectMethod="SelectMember"> <ItemTemplate> <fieldset> ... </fieldset> </ItemTemplate> <EditItemTemplate> <fieldset> <ul> <li> <asp:Label ID="lblFirstName" runat="server" AssociatedControlID="txtFirstName">FirstName:</asp:Label> <asp:TextBox runat="server" ID="txtFirstName" Text='<%#: BindItem.FirstName %>' /> </li> <li> <asp:Label ID="lblLastname" runat="server" AssociatedControlID="txtLastName">LastName:</asp:Label> <asp:TextBox runat="server" ID="txtLastName" Text='<%# BindItem.LastName %>' /> </li> <li> <asp:Label ID="lblGender" runat="server" AssociatedControlID="cmbGender">Gender:</asp:Label> <asp:DropDownList runat="server" ID="cmbGender" SelectMethod="SelectGender" SelectedItem='<%# BindItem.Gender %>' /> </li> </ul> <br /> <ul> <li> <asp:Button ID="btnSave" runat="server" CommandName="Update" Text="Save" /> <asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" /> </li> </ul> </fieldset> </EditItemTemplate> <InsertItemTemplate> <fieldset> ... </fieldset> </InsertItemTemplate> </asp:FormView>Is this somehow possible, or do I need another approach?
DROPDOWNList