• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5408
  • 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:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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