Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 1st, 2014, 11:31 PM
Authorized User
Points: 46, Level: 1
Points: 46, Level: 1 Points: 46, Level: 1 Points: 46, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
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
Reply With Quote
  #2 (permalink)  
Old February 5th, 2014, 01:10 AM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
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"
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 04:35 AM.

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