• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5356
  • Last Modified:

ASPx GridView Edit Template with dropDown

I want to be able to put a drop down box in an editable datagrid, Ive managed to get a dropdown box, and with the values, but when I click on 'update' it doesnt update the row in the database. and doesnt show the value of the field as the selected item in the drop down. I know I havnt set it, but dont know how to set it.

Any ideas?

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="priID" DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display.">
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="priID" HeaderText="priID" ReadOnly="True" 
                SortExpression="priID" />
            <asp:BoundField DataField="Username" HeaderText="Username" 
                SortExpression="Username" />
            <asp:BoundField DataField="Password" HeaderText="Password" 
                SortExpression="Password" />
            <asp:BoundField DataField="PhoneNo" HeaderText="PhoneNo" 
                SortExpression="PhoneNo" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="Company" HeaderText="Company" 
                SortExpression="Company" />
            <asp:TemplateField HeaderText="StartingDir" SortExpression="StartingDir">
                    <asp:DropDownList ID="StartingDir" runat="server" 
                        <asp:ListItem Enabled="True" Selected="True">Please Select</asp:ListItem>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>" 
                        SelectCommand="SELECT directory FROM Directories"></asp:SqlDataSource>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("StartingDir") %>'></asp:Label>
            <asp:CheckBoxField DataField="AllowUpload" HeaderText="AllowUpload" 
                SortExpression="AllowUpload" />

Open in new window

1 Solution
tonelm54Author Commented:
David H.H.LeeCommented:
Hi tonelm54,
Can i see you update statement? You can check on GridView's RowCommand event and perform the update parameters accordingly. Then, proceed the GridView's RowUpdating event to update the datasource. That should did the trick.

GridView's RowCommand

GridView's RowUpdating

More details:


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now