By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

FormView Edit Template Issue

P: n/a
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.ArgumentOutOfRangeException: '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:

[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is
invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +975
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelec t() +32
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.FormView.CreateChildCont rols(IEnumerable
dataSource, Boolean dataBinding) +3047
System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +90
System.Web.UI.WebControls.FormView.PerformDataBind ing(IEnumerable data)
+30
System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +126
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments,
DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.Perform Select() +154
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.WebControls.FormView.DataBind() +23
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +91
System.Web.UI.WebControls.FormView.EnsureDataBound () +176
System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls()
+101
System.Web.UI.Control.EnsureChildControls() +134
System.Web.UI.Control.PreRenderRecursiveInternal() +109
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4435


Feb 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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:DropDownList ID="CountrysDropDownList" runat="server"
Font-Size="xx-small" DataSourceID="CountrysSqlDataSource"
DataTextField="CountryName" DataValueField="pk_CountryId"
OnDataBound="CountrysDropDownList_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 CountrysDropDownList_DataBound(ByVal sender As Object, ByVal e
As System.EventArgs)
Try
Dim CountrysDropDownList As DropDownList = CType(sender,
DropDownList)
Dim View As Data.DataRowView = FormView1.DataItem
CountrysDropDownList.SelectedValue =
View.Item("fk_CountryId").ToString
Catch ex As Exception
Master.ProcessException("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*****@newsgroups.nospam> wrote in message
news:%2****************@tk2msftngp13.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.ArgumentOutOfRangeException: '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:

[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is
invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +975
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelec t() +32
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.FormView.CreateChildCont rols(IEnumerable
dataSource, Boolean dataBinding) +3047

System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +90
System.Web.UI.WebControls.FormView.PerformDataBind ing(IEnumerable data)
+30

System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +126
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments,
DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.Perform Select() +154
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.WebControls.FormView.DataBind() +23
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +91
System.Web.UI.WebControls.FormView.EnsureDataBound () +176

System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls()
+101
System.Web.UI.Control.EnsureChildControls() +134
System.Web.UI.Control.PreRenderRecursiveInternal() +109
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4435

Feb 4 '06 #2

P: n/a
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**************@tk2msftngp13.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:DropDownList ID="CountrysDropDownList" runat="server"
Font-Size="xx-small" DataSourceID="CountrysSqlDataSource"
DataTextField="CountryName" DataValueField="pk_CountryId"
OnDataBound="CountrysDropDownList_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 CountrysDropDownList_DataBound(ByVal sender As Object, ByVal
e As System.EventArgs)
Try
Dim CountrysDropDownList As DropDownList = CType(sender,
DropDownList)
Dim View As Data.DataRowView = FormView1.DataItem
CountrysDropDownList.SelectedValue =
View.Item("fk_CountryId").ToString
Catch ex As Exception
Master.ProcessException("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*****@newsgroups.nospam> wrote in message
news:%2****************@tk2msftngp13.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.ArgumentOutOfRangeException: '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:

[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which
is invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +975
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelec t() +32
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.FormView.CreateChildCont rols(IEnumerable
dataSource, Boolean dataBinding) +3047

System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +90
System.Web.UI.WebControls.FormView.PerformDataBind ing(IEnumerable data)
+30

System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +126
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments
arguments, DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.Perform Select() +154
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.WebControls.FormView.DataBind() +23
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +91
System.Web.UI.WebControls.FormView.EnsureDataBound () +176

System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls()
+101
System.Web.UI.Control.EnsureChildControls() +134
System.Web.UI.Control.PreRenderRecursiveInternal() +109
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+4435


Feb 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.