Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 1st, 2014, 11:31 PM
Authorized User
Join Date: Jan 2014
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default Binding a dropdown list control within ListView

Hey everyone,

I have a ListView control working all nice and neat, bound to a sql data source.

I inserted a second SQL data source to populate a dropdown list within the listview control.

I have the listview control in grid view. On the insertitemtemplate configuration, I am trying to override the text box for "cTypeID" with a dropdown list that has the secondary sql source as its datasource.

You can see from the code below I am trying to get rid of the cTypeIDTextBox and replace it with cTypeDD. It isn't working so I didn't get rid of the textbox yet.
<tr style="">
<td><asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /><asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
<td><asp:Label ID="cIDLabel1" runat="server" Text='<%# Eval("cID") %>' /></td>
<td><asp:TextBox ID="cDateTextBox" runat="server" Text='<%# Bind("cDate") %>' /></td>
<td><asp:DropDownList ID="cTypeDD" runat="server" DataSourceID="CruiseTypes" DataTextField='<%# DataBinder.Eval(Container.DataItem,"tName") %>' ></asp:DropDownList></td>
<td><asp:TextBox ID="cTypeIDTextBox" runat="server" Text='<%# Bind("cTypeID") %>' /></td>
The second SQL Datasource is defined as follows:
<asp:SqlDataSource ID="CruiseTypes" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
SelectCommand="SELECT [tID], [tName] FROM [tbl_Config_Types]"></asp:SqlDataSource>
The error I get is the following:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'tName'.

I know it has this column - I defined it in the query. Why isn't this working?

Thanks in advance for your help
Old February 5th, 2014, 01:10 AM
Friend of Wrox
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts

The DataTextField is the name of the field or property that contains the text to bind to in the text field of the ListItem. The DataValueField is the name of field or property that contains the value to bind to the value field of the ListItem. i.e. DataTextField="tName" DataValueField="tID"

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding dropdown list in code behind with hand coding sophia BOOK: Beginning ASP.NET 4 : in C# and VB 1 December 27th, 2011 05:10 PM
Binding ComboBox inside ListView problem gunnjamie Windows Presentation Foundation 1 July 17th, 2008 02:13 PM
CheckBox binding in ListView - Multiple events! dweezilb Windows Presentation Foundation 1 April 22nd, 2007 06:39 PM
Datagrid binding two dropdown inkrajesh ASP.NET 1.0 and 1.1 Basics 0 July 18th, 2006 10:46 PM
Binding a comboBox to update a listView Amethyst1984 VB How-To 2 February 28th, 2006 03:07 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.