Solved

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

Posted on 2008-10-06
4
4,008 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
4 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Not showing page correctly 3 31
Message not shown 5 34
Where to download and how to install sqldmo.dll 5 38
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now