3
Next, I have a table "animals" with field "sex" (varchar(1)). In it I Seto M or F, for Male or Female.
Use detailsView to show/edit these fields and would like to have a Dropdownlist in Edittemplate with the Male or Female options and when clicking edit, update in the database with M or F.
How do I do?
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" 
In case I use Sqldatasource, is there any way using it?
– GutoSchiavon