Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 August 20th, 2013, 10:06 AM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default DropDownList with several hard coded values inside FormView

In Chapter 13 we can include DropDownList in EditItemTemplate in FormView, DetailsView or GridView and Bind it to DataSource, which select data from database. It is possible to include DropDownList in EditItemTemplate with several hard coded values without selecting data from database? How we can implement it?
 
Old August 20th, 2013, 10:30 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You certainly can. Just don't associate a data control, and add the items in Markup directly.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 20th, 2013, 11:11 AM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you Imar.
Could you show example how to do it with DropDownList inside EditItemTemplate? Appreciate your help.
 
Old August 20th, 2013, 11:22 AM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

I already was able do it using ListItem control inside DropDownlist in EditItemTemplate, the same as for regular DropDownList:
<
asp:ListItem>Letter</asp:ListItem>, according to your advice.
Thank you very much!!!
 
Old August 20th, 2013, 11:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Just like any other DDL:

Code:
<asp:DropDownList id="ColorList" runat="server">
  <asp:ListItem Value="White"> White </asp:ListItem>
  <asp:ListItem Value="Silver"> Silver </asp:ListItem>
  <asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
</asp:DropDownList>
Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 20th, 2013, 12:32 PM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

Imar,

Thank you again for your excellent help!!!!!
 
Old August 21st, 2013, 11:54 AM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

DropDownList with HardCoded values works fine inside ItemTemplate within FormView, but inside EditItemTeplate it does not save selected value when click Update button.
 
Old August 21st, 2013, 12:15 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you bind the selected value using the SelectedValue property and a Bind statement?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 21st, 2013, 12:37 PM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, I tried to Bind using Selected Value, this is my code from markup:
<asp:DropDownListID="ddl_how_education_provided"runat="server"DataTextField="Education"DataValueField="Education"SelectedValue='<%#Bind("Education") %>'>
<asp:ListItem>-- Select Education --</asp:ListItem>
<asp:ListItem>Letter</asp:ListItem>
<asp:ListItem>Telephone conversation</asp:ListItem>
<asp:ListItem>Office Visit</asp:ListItem>
</asp:DropDownList>

but got error: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Education'

Might be I need to use FormView DataBinding event, use FindControl function inside this event to find DropDownList inside FormView and then use DataBind?
 
Old August 21st, 2013, 02:12 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You should get rid of the DataTextField and DataValueField properties as they are used in data binding scenarios.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList Inside FormView Problem frogosteve ASP.NET 2.0 Basics 0 April 12th, 2007 10:30 AM
Hard coded paths pauliehaha Classic ASP Professional 8 February 6th, 2007 06:48 PM
Hard coded examples etrump BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 March 1st, 2006 02:10 PM
The solution hard coded "ThePhile" jackchua BOOK: ASP.NET Website Programming Problem-Design-Solution 3 October 20th, 2004 11:25 PM





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