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

August 20th, 2013, 10:06 AM
|
|
Authorized User
|
|
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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?
|
|

August 20th, 2013, 10:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You certainly can. Just don't associate a data control, and add the items in Markup directly.
Hope this helps,
Imar
|
|

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

August 20th, 2013, 11:22 AM
|
|
Authorized User
|
|
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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!!!
|
|

August 20th, 2013, 11:23 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 20th, 2013, 12:32 PM
|
|
Authorized User
|
|
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Imar,
Thank you again for your excellent help!!!!!
|
|

August 21st, 2013, 11:54 AM
|
|
Authorized User
|
|
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
|
|
DropDownList with HardCoded values works fine inside ItemTemplate within FormView, but inside EditItemTeplate it does not save selected value when click Update button.
|
|

August 21st, 2013, 12:15 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did you bind the selected value using the SelectedValue property and a Bind statement?
Imar
|
|

August 21st, 2013, 12:37 PM
|
|
Authorized User
|
|
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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?
|
|

August 21st, 2013, 02:12 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You should get rid of the DataTextField and DataValueField properties as they are used in data binding scenarios.
Cheers,
Imar
|
|
 |
|