• 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.">
        <Columns>
            <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">
                <EditItemTemplate>
                    <asp:DropDownList ID="StartingDir" runat="server" 
                        DataSourceID="SqlDataSource1" 
                        DataTextField="directory" 
                        DataValueField="directory"
                        AppendDataBoundItems="true">
                        <asp:ListItem Enabled="True" Selected="True">Please Select</asp:ListItem>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>" 
                        SelectCommand="SELECT directory FROM Directories"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("StartingDir") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CheckBoxField DataField="AllowUpload" HeaderText="AllowUpload" 
                SortExpression="AllowUpload" />
        </Columns>
    </asp:GridView>

Open in new window

0
tonelm54
Asked:
tonelm54
1 Solution
 
tonelm54Author Commented:
...
0
 
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
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspxv

GridView's RowUpdating
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx

More details:
http://www.codeproject.com/KB/aspnet/GridviewItemDropdown.aspx

0
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