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

Using a dropdown list on the edit item template in a list view ASP.NET 3.5


I am trying to add a dropdown list to a list view. When I try to use the findcontrol method of the list view to get a handle to the dropdown list it only appears to be searching the item template. I cannot get a handle to the dropdown list in the Edit item template.

Has anyone used a dropdown to edit data using a list view??

Your help will be much appreciated.

<td><asp:DropDownList ID="ddl_ProjectStatus"  runat="server" /></td>
Private Sub lv_ProjectList_ItemEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewEditEventArgs) Handles lv_ProjectList.ItemEditing
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT CodeDetail,Description FROM CodeDetail WHERE DELETED = 0", conn)
        Dim ds As New DataSet
        Dim ddl As DropDownList
        ' Get a handle to the ddl_ProjectStatus DropDownList control
        ddl = lv_ProjectList.Items(e.NewEditIndex).FindControl("ddl_ProjectStatus")
        'Make sure we have the handle !
        If Not (ddl Is Nothing) Then
            ddl.DataSource = ds
            ddl.DataTextField = "Description"
            ddl.DataValueField = "CodeDetail"
        End If
    End Sub

Open in new window

1 Solution
Gyanendra SinghArchitectCommented:
attaching sample, hope that will help you

<asp:TemplateField HeaderText="User Name">
<asp:Label ID="lbl1" runat="server" Text='<%# Bind("username")%>' />
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true"
DataSourceID="SqlDataSource1" DataValueField=username AutoPostBack="True" SelectedValue='<%# Bind("username")%>'>
<asp:ListItem Value="">Select an Item</asp:ListItem>

Open in new window

riclandyAuthor Commented:
Thanks, Sorry I haven't replied sooner, I've just arrived back from holiday.

I'll try this tomorrow and post the result.
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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