Solved

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

Posted on 2008-10-06
4
3,985 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

8 Experts available now in Live!

Get 1:1 Help Now