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 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 20th, 2013, 10:06 AM
bpl bpl is offline
Authorized User
Points: 86, Level: 1
Points: 86, Level: 1 Points: 86, Level: 1 Points: 86, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #2 (permalink)  
Old August 20th, 2013, 10:30 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
  #3 (permalink)  
Old August 20th, 2013, 11:11 AM
bpl bpl is offline
Authorized User
Points: 86, Level: 1
Points: 86, Level: 1 Points: 86, Level: 1 Points: 86, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #4 (permalink)  
Old August 20th, 2013, 11:22 AM
bpl bpl is offline
Authorized User
Points: 86, Level: 1
Points: 86, Level: 1 Points: 86, Level: 1 Points: 86, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!!!
Reply With Quote
  #5 (permalink)  
Old August 20th, 2013, 11:23 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
  #6 (permalink)  
Old August 20th, 2013, 12:32 PM
bpl bpl is offline
Authorized User
Points: 86, Level: 1
Points: 86, Level: 1 Points: 86, Level: 1 Points: 86, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

Imar,

Thank you again for your excellent help!!!!!
Reply With Quote
  #7 (permalink)  
Old August 21st, 2013, 11:54 AM
bpl bpl is offline
Authorized User
Points: 86, Level: 1
Points: 86, Level: 1 Points: 86, Level: 1 Points: 86, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #8 (permalink)  
Old August 21st, 2013, 12:15 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
  #9 (permalink)  
Old August 21st, 2013, 12:37 PM
bpl bpl is offline
Authorized User
Points: 86, Level: 1
Points: 86, Level: 1 Points: 86, Level: 1 Points: 86, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #10 (permalink)  
Old August 21st, 2013, 02:12 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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!
Reply With Quote
Reply


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
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



All times are GMT -4. The time now is 04:18 PM.


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