473,763 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FormView Edit Template Issue

Hello,

I am creating an edit template for a FormView control, changing one of the
textboxes to a dropdown box. The dropdown will be populated from a simple
table with the primary key, and a description (i.e. a colors table, so there
is a colors ID and a color description).

The data source the FormView is pulling data from stores (in this example)
the primary key for the colors table. My ultimate goal is when the FormView
goes into an Edit mode that the description of the color will be set
correctly based off of the ID provided in the record the FormView is
displaying. As an example, if the colors ID is 1, and that happens to be
blue, the dropdown will default to the value of blue.

I've been trying various ways to get this to work, and am not having much
luck. Is there an example somewhere that someone is aware of to show how to
do this? The error I keep getting is below. I'm thinking it has to do with
the order the controls bind, but I do not know for sure. Any suggestions
would be appreciated.

Thanks
Paul

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Argument OutOfRangeExcep tion: 'DropDownList1' has a
SelectedValue which is invalid because it does not exist in the list of
items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRa ngeException: 'DropDownList1' has a SelectedValue which is
invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.W ebControls.List Control.Perform DataBinding(IEn umerable
dataSource) +975
System.Web.UI.W ebControls.List Control.OnDataB inding(EventArg s e) +80
System.Web.UI.W ebControls.List Control.Perform Select() +32
System.Web.UI.W ebControls.Base DataBoundContro l.DataBind() +99
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.W ebControls.Form View.CreateChil dControls(IEnum erable
dataSource, Boolean dataBinding) +3047
System.Web.UI.W ebControls.Comp ositeDataBoundC ontrol.PerformD ataBinding(IEnu merable
data) +90
System.Web.UI.W ebControls.Form View.PerformDat aBinding(IEnume rable data)
+30
System.Web.UI.W ebControls.Data BoundControl.On DataSourceViewS electCallback(I Enumerable
data) +126
System.Web.UI.D ataSourceView.S elect(DataSourc eSelectArgument s arguments,
DataSourceViewS electCallback callback) +98
System.Web.UI.W ebControls.Data BoundControl.Pe rformSelect() +154
System.Web.UI.W ebControls.Base DataBoundContro l.DataBind() +99
System.Web.UI.W ebControls.Form View.DataBind() +23
System.Web.UI.W ebControls.Base DataBoundContro l.EnsureDataBou nd() +91
System.Web.UI.W ebControls.Form View.EnsureData Bound() +176
System.Web.UI.W ebControls.Comp ositeDataBoundC ontrol.CreateCh ildControls()
+101
System.Web.UI.C ontrol.EnsureCh ildControls() +134
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +109
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +233
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +233
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +4435


Feb 3 '06 #1
2 8742
Paul,

I'm doing exactly what you describe with a country dropdownlist.

I'm using the list's Databound event, which fires after the list's
databinding has completed so that all the items are in the list before I try
to set the value:

1) In the .aspx file's source view set the drop down's OnDataBound event to
call the correct subroutine. Note that the DataSourceId is calling one of
the new .NET 2.0 databinding datasource objects and that the DataText and
DataValue Fields are being set to columns being returned by that
datasource's select statement in order to generate the dropdown's list
items.

<asp:DropDownLi st ID="CountrysDro pDownList" runat="server"
Font-Size="xx-small" DataSourceID="C ountrysSqlDataS ource"
DataTextField=" CountryName" DataValueField= "pk_Country Id"
OnDataBound="Co untrysDropDownL ist_DataBound">

2) In the codebehind the cast the sender as the dropdownlist and then use
the form view's dataitem (a datarowview) to get the bound value for the
dropdownlist.

Protected Sub CountrysDropDow nList_DataBound (ByVal sender As Object, ByVal e
As System.EventArg s)
Try
Dim CountrysDropDow nList As DropDownList = CType(sender,
DropDownList)
Dim View As Data.DataRowVie w = FormView1.DataI tem
CountrysDropDow nList.SelectedV alue =
View.Item("fk_C ountryId").ToSt ring
Catch ex As Exception
Master.ProcessE xception("There was an error while selecting the
country for edit mode:", ex)
End Try
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"P. Yanzick" <Ar*****@newsgr oups.nospam> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hello,

I am creating an edit template for a FormView control, changing one of the
textboxes to a dropdown box. The dropdown will be populated from a simple
table with the primary key, and a description (i.e. a colors table, so
there is a colors ID and a color description).

The data source the FormView is pulling data from stores (in this example)
the primary key for the colors table. My ultimate goal is when the
FormView goes into an Edit mode that the description of the color will be
set correctly based off of the ID provided in the record the FormView is
displaying. As an example, if the colors ID is 1, and that happens to be
blue, the dropdown will default to the value of blue.

I've been trying various ways to get this to work, and am not having much
luck. Is there an example somewhere that someone is aware of to show how
to do this? The error I keep getting is below. I'm thinking it has to do
with the order the controls bind, but I do not know for sure. Any
suggestions would be appreciated.

Thanks
Paul

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Argument OutOfRangeExcep tion: 'DropDownList1' has
a SelectedValue which is invalid because it does not exist in the list of
items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRa ngeException: 'DropDownList1' has a SelectedValue which is
invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.W ebControls.List Control.Perform DataBinding(IEn umerable
dataSource) +975
System.Web.UI.W ebControls.List Control.OnDataB inding(EventArg s e) +80
System.Web.UI.W ebControls.List Control.Perform Select() +32
System.Web.UI.W ebControls.Base DataBoundContro l.DataBind() +99
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.W ebControls.Form View.CreateChil dControls(IEnum erable
dataSource, Boolean dataBinding) +3047

System.Web.UI.W ebControls.Comp ositeDataBoundC ontrol.PerformD ataBinding(IEnu merable
data) +90
System.Web.UI.W ebControls.Form View.PerformDat aBinding(IEnume rable data)
+30

System.Web.UI.W ebControls.Data BoundControl.On DataSourceViewS electCallback(I Enumerable
data) +126
System.Web.UI.D ataSourceView.S elect(DataSourc eSelectArgument s arguments,
DataSourceViewS electCallback callback) +98
System.Web.UI.W ebControls.Data BoundControl.Pe rformSelect() +154
System.Web.UI.W ebControls.Base DataBoundContro l.DataBind() +99
System.Web.UI.W ebControls.Form View.DataBind() +23
System.Web.UI.W ebControls.Base DataBoundContro l.EnsureDataBou nd() +91
System.Web.UI.W ebControls.Form View.EnsureData Bound() +176

System.Web.UI.W ebControls.Comp ositeDataBoundC ontrol.CreateCh ildControls()
+101
System.Web.UI.C ontrol.EnsureCh ildControls() +134
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +109
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +233
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +233
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +4435

Feb 4 '06 #2
Hello,

Thanks for the suggestion! I did manage to get it working in a different
way than you did actually. I was able to do it all via the interface
without having to do any coding at all! For some reason, I had to create a
new project, but once I did so, it worked fine.

Thanks for your help!

Paul
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote in
message news:u5******** ******@tk2msftn gp13.phx.gbl...
Paul,

I'm doing exactly what you describe with a country dropdownlist.

I'm using the list's Databound event, which fires after the list's
databinding has completed so that all the items are in the list before I
try to set the value:

1) In the .aspx file's source view set the drop down's OnDataBound event
to call the correct subroutine. Note that the DataSourceId is calling one
of the new .NET 2.0 databinding datasource objects and that the DataText
and DataValue Fields are being set to columns being returned by that
datasource's select statement in order to generate the dropdown's list
items.

<asp:DropDownLi st ID="CountrysDro pDownList" runat="server"
Font-Size="xx-small" DataSourceID="C ountrysSqlDataS ource"
DataTextField=" CountryName" DataValueField= "pk_Country Id"
OnDataBound="Co untrysDropDownL ist_DataBound">

2) In the codebehind the cast the sender as the dropdownlist and then use
the form view's dataitem (a datarowview) to get the bound value for the
dropdownlist.

Protected Sub CountrysDropDow nList_DataBound (ByVal sender As Object, ByVal
e As System.EventArg s)
Try
Dim CountrysDropDow nList As DropDownList = CType(sender,
DropDownList)
Dim View As Data.DataRowVie w = FormView1.DataI tem
CountrysDropDow nList.SelectedV alue =
View.Item("fk_C ountryId").ToSt ring
Catch ex As Exception
Master.ProcessE xception("There was an error while selecting the
country for edit mode:", ex)
End Try
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"P. Yanzick" <Ar*****@newsgr oups.nospam> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hello,

I am creating an edit template for a FormView control, changing one of
the textboxes to a dropdown box. The dropdown will be populated from a
simple table with the primary key, and a description (i.e. a colors
table, so there is a colors ID and a color description).

The data source the FormView is pulling data from stores (in this
example) the primary key for the colors table. My ultimate goal is when
the FormView goes into an Edit mode that the description of the color
will be set correctly based off of the ID provided in the record the
FormView is displaying. As an example, if the colors ID is 1, and that
happens to be blue, the dropdown will default to the value of blue.

I've been trying various ways to get this to work, and am not having much
luck. Is there an example somewhere that someone is aware of to show how
to do this? The error I keep getting is below. I'm thinking it has to
do with the order the controls bind, but I do not know for sure. Any
suggestions would be appreciated.

Thanks
Paul

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Argument OutOfRangeExcep tion: 'DropDownList1'
has a SelectedValue which is invalid because it does not exist in the
list of items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRa ngeException: 'DropDownList1' has a SelectedValue which
is invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.W ebControls.List Control.Perform DataBinding(IEn umerable
dataSource) +975
System.Web.UI.W ebControls.List Control.OnDataB inding(EventArg s e) +80
System.Web.UI.W ebControls.List Control.Perform Select() +32
System.Web.UI.W ebControls.Base DataBoundContro l.DataBind() +99
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.C ontrol.DataBind () +31
System.Web.UI.C ontrol.DataBind Children() +236
System.Web.UI.C ontrol.DataBind (Boolean raiseOnDataBind ing) +178
System.Web.UI.W ebControls.Form View.CreateChil dControls(IEnum erable
dataSource, Boolean dataBinding) +3047

System.Web.UI.W ebControls.Comp ositeDataBoundC ontrol.PerformD ataBinding(IEnu merable
data) +90
System.Web.UI.W ebControls.Form View.PerformDat aBinding(IEnume rable data)
+30

System.Web.UI.W ebControls.Data BoundControl.On DataSourceViewS electCallback(I Enumerable
data) +126
System.Web.UI.D ataSourceView.S elect(DataSourc eSelectArgument s
arguments, DataSourceViewS electCallback callback) +98
System.Web.UI.W ebControls.Data BoundControl.Pe rformSelect() +154
System.Web.UI.W ebControls.Base DataBoundContro l.DataBind() +99
System.Web.UI.W ebControls.Form View.DataBind() +23
System.Web.UI.W ebControls.Base DataBoundContro l.EnsureDataBou nd() +91
System.Web.UI.W ebControls.Form View.EnsureData Bound() +176

System.Web.UI.W ebControls.Comp ositeDataBoundC ontrol.CreateCh ildControls()
+101
System.Web.UI.C ontrol.EnsureCh ildControls() +134
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +109
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +233
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +233
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
+4435


Feb 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2817
by: Dick | last post by:
How do I set the focus to a control that is a child to a FormView? I've tried the obvious (below) and lots of variations but none seam to work! Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.FormView1.Row.FindControl("TextBox1").Focus() End Sub
7
4353
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the sqldatasource of the formview. If i put this textboxes outside the table everything works well, but as soon as i put them inside the table (in order to organize the layout in the right way) they doesn't work. They works only as eval() and not bind()...
0
1117
by: Chris | last post by:
I am using the formview control. Within its edit template I have a treeview, which I populate programatically. Initially I had an item template in which I had a button, which triggered the edit template. The treeview was populated with the following code Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As System.EventArgs) If FormView1.CurrentMode = FormViewMode.Edit Or FormView1.CurrentMode = FormViewMode.Insert Then...
3
4773
by: Geek | last post by:
Guys, I am working on a project, and I thought using FormView will help good but I am running into a issue. What I have done is that in Form View in Footer template icluded a Link Button which is servind as an edit command. When user click it should change the Formview to Edit mode. But when I click first on it is changing the mode to edit, it is not diplaying the Edit Item template, I have to click again in order to get into Edit Item...
2
8641
by: wikkiwikkiwaa | last post by:
hello, i am trying to access controls inside my formview1 nested inside loginview1. you cannot access the formview1 unless you are properly logged in. for loginview1, that seems to be fairly simple. a label control would be: Label label1 = (Label)loginview1.FindControl("nameoflabel"); then i get to the data that was bound to that control.
8
7079
by: BB | last post by:
Hi, I am using FormView Contol, TextBox (Hidden ) and Submit button whose caption is "View Page" in my aspx page. Here is what I am tryin to do.When page loads I generate dynamic url in text box . I want to append exisitng value in Formview field "CustomeID" to url. When userclicks on "view page" ,new window is opened with dynamic url. I am able to do generarting url dynamically, but dont know how i can do rest of the things. Any idea?
1
10274
by: SteveT | last post by:
Before I pull out what little hair I have left, I'm swallowing my pride and asking the Oracles of .Net: I'm trying to set a property in a dropdown list control in a FormView, based on a session parameter. The control is in the edit template of the FormView, which is not visible from the view template. I'm able to change properties of controls on the view template. However, when trying to set them on the edit template the control...
1
1740
by: mans | last post by:
Hello, I want to enable the edit template in a FormView from program. How can I do this? The FormView bound to a table and I don't want that it do the edit/add/delete but I control when it can do this.
1
4618
by: Paulo | last post by:
Hi, I have a aspx with a a FormView on left wich opens insert template as default containing all the TextsBox, Combos, etc, and on right a GridView listing the stored itens (ID column key)... When the user clicks on gridview, it must open the formview in edit mode with all the objects filled... how can I do that? another question, if there is need to add more itens on the formview insert template, must it be added manually on edit...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.