Next, I have a table "animals" with field "sex" (varchar (1)). In it I hedge M or F, for Male or Female.
Use detailsView to show / edit these fields and would like to have a DropDownList in the EditTemplate with the options Male or Female and when you click edit, update in the database with M or F.
How do I do it?
My code:
<asp:TemplateField HeaderText="Sexo:" SortExpression="sexo">
<EditItemTemplate>
<asp:DropDownList ID="sexoDrop" runat="server">
<asp:ListItem Value="M">Macho</asp:ListItem>
<asp:ListItem Value="F">Fêmea</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("sexo") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("sexo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<UpdateParameters>
<asp:ControlParameter Name="sexo" ControlID="sexoDrop" PropertyName="SelectedValue" />
</UpdateParameters>
UpdateCommand="UPDATE [animais] SET [sexo] = @sexo WHERE [id] = @original_id"