Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-06
4
Medium Priority
?
4,167 Views
Last Modified: 2013-11-08
Hi,

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.

<EditItemTemplate>
<td><asp:DropDownList ID="ddl_ProjectStatus"  runat="server" /></td>
</EditItemTemplate>
 
 
 
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
            da.Fill(ds)
            ddl.DataSource = ds
            ddl.DataTextField = "Description"
            ddl.DataValueField = "CodeDetail"
            ddl.DataBind()
        End If
    End Sub

Open in new window

0
Comment
Question by:riclandy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 1000 total points
ID: 22684630
attaching sample, hope that will help you


<asp:TemplateField HeaderText="User Name">
<ItemTemplate>
<asp:Label ID="lbl1" runat="server" Text='<%# Bind("username")%>' />
</ItemTemplate>
<EditItemTemplate>
<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>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField> 

Open in new window

0
 

Author Comment

by:riclandy
ID: 22712218
Thanks, Sorry I haven't replied sooner, I've just arrived back from holiday.

I'll try this tomorrow and post the result.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question