Formview DropDownList bug??

  • Thread starter Karl-Inge Reknes
  • Start date
K

Karl-Inge Reknes

I have a page with a formview control who datasource is a objectdatasource.
In edit mode template I have tree dropdownlist; Year, Month and Day. Each
dropdownlist i populated from an objectdatasource object and is bind to
column in the formview control objectdatasource. The objectdatasource object
for dropdownlist Day have 2 arguments; Year and Month. The dropdownlist day
is populated with correct number of days for that month and year.

When changing Year or Month this error appear:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

If I remove the binding for dropdownlist Day the error doesn’t appear, but
then I not able to save the Day Column

Is there anybody who can help me?

Karl-Inge Reknes
 
P

Phillip Williams

Hi Karl-Inge,

I met the same situation in using dependent dropdownlist within the
EditItemTemplate where 2-way databinding is attempted. The solution is to
remove the 2-way databinding from the dependent dropdownlist and replace it
with customized code during processing the ItemUpdating event.

For example if one had 2 dropdownlists where one had the country and the
other had the City; where the City dropdownlist re-populate every time the
Country selection is changed, then upon ItemUpdating I would do something
like this:
void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
string strCity=
((DropDownList))((FormView)sender).FindControl("ddlCity")).SelectedValue;
e.NewValues[1] = strCity; //assuming the second value being updated is
the City
e.Cancel = false; //this would confirm that the update should continue
}
 
P

Phillip Williams

I missed to note that in the solution described below I have used a label
that was 2-way databound to the City instead of the dropdownlist. The label
was styled as hidden. Its purpose is to keep the number of e.NewValues to
the same as if I had the dropdownlist 2-way databound.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Phillip Williams said:
Hi Karl-Inge,

I met the same situation in using dependent dropdownlist within the
EditItemTemplate where 2-way databinding is attempted. The solution is to
remove the 2-way databinding from the dependent dropdownlist and replace it
with customized code during processing the ItemUpdating event.

For example if one had 2 dropdownlists where one had the country and the
other had the City; where the City dropdownlist re-populate every time the
Country selection is changed, then upon ItemUpdating I would do something
like this:
void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
string strCity=
((DropDownList))((FormView)sender).FindControl("ddlCity")).SelectedValue;
e.NewValues[1] = strCity; //assuming the second value being updated is
the City
e.Cancel = false; //this would confirm that the update should continue
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Karl-Inge Reknes said:
I have a page with a formview control who datasource is a objectdatasource.
In edit mode template I have tree dropdownlist; Year, Month and Day. Each
dropdownlist i populated from an objectdatasource object and is bind to
column in the formview control objectdatasource. The objectdatasource object
for dropdownlist Day have 2 arguments; Year and Month. The dropdownlist day
is populated with correct number of days for that month and year.

When changing Year or Month this error appear:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

If I remove the binding for dropdownlist Day the error doesn’t appear, but
then I not able to save the Day Column

Is there anybody who can help me?

Karl-Inge Reknes
 
K

Karl-Inge Reknes

Thanks Phillip.

Karl-Inge

Phillip Williams said:
I missed to note that in the solution described below I have used a label
that was 2-way databound to the City instead of the dropdownlist. The label
was styled as hidden. Its purpose is to keep the number of e.NewValues to
the same as if I had the dropdownlist 2-way databound.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Phillip Williams said:
Hi Karl-Inge,

I met the same situation in using dependent dropdownlist within the
EditItemTemplate where 2-way databinding is attempted. The solution is to
remove the 2-way databinding from the dependent dropdownlist and replace it
with customized code during processing the ItemUpdating event.

For example if one had 2 dropdownlists where one had the country and the
other had the City; where the City dropdownlist re-populate every time the
Country selection is changed, then upon ItemUpdating I would do something
like this:
void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
string strCity=
((DropDownList))((FormView)sender).FindControl("ddlCity")).SelectedValue;
e.NewValues[1] = strCity; //assuming the second value being updated is
the City
e.Cancel = false; //this would confirm that the update should continue
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Karl-Inge Reknes said:
I have a page with a formview control who datasource is a objectdatasource.
In edit mode template I have tree dropdownlist; Year, Month and Day. Each
dropdownlist i populated from an objectdatasource object and is bind to
column in the formview control objectdatasource. The objectdatasource object
for dropdownlist Day have 2 arguments; Year and Month. The dropdownlist day
is populated with correct number of days for that month and year.

When changing Year or Month this error appear:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

If I remove the binding for dropdownlist Day the error doesn’t appear, but
then I not able to save the Day Column

Is there anybody who can help me?

Karl-Inge Reknes
 
P

Phillip Williams

You are quite welcome, Karl-Inge. I just managed to put a demo of the
solution I proposed below, with the complete source code, at this link:
http://www.webswapp.com/demos/formView1.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Karl-Inge Reknes said:
Thanks Phillip.

Karl-Inge

Phillip Williams said:
I missed to note that in the solution described below I have used a label
that was 2-way databound to the City instead of the dropdownlist. The label
was styled as hidden. Its purpose is to keep the number of e.NewValues to
the same as if I had the dropdownlist 2-way databound.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Phillip Williams said:
Hi Karl-Inge,

I met the same situation in using dependent dropdownlist within the
EditItemTemplate where 2-way databinding is attempted. The solution is to
remove the 2-way databinding from the dependent dropdownlist and replace it
with customized code during processing the ItemUpdating event.

For example if one had 2 dropdownlists where one had the country and the
other had the City; where the City dropdownlist re-populate every time the
Country selection is changed, then upon ItemUpdating I would do something
like this:
void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
string strCity=
((DropDownList))((FormView)sender).FindControl("ddlCity")).SelectedValue;
e.NewValues[1] = strCity; //assuming the second value being updated is
the City
e.Cancel = false; //this would confirm that the update should continue
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a page with a formview control who datasource is a objectdatasource.
In edit mode template I have tree dropdownlist; Year, Month and Day. Each
dropdownlist i populated from an objectdatasource object and is bind to
column in the formview control objectdatasource. The objectdatasource object
for dropdownlist Day have 2 arguments; Year and Month. The dropdownlist day
is populated with correct number of days for that month and year.

When changing Year or Month this error appear:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

If I remove the binding for dropdownlist Day the error doesn’t appear, but
then I not able to save the Day Column

Is there anybody who can help me?

Karl-Inge Reknes
 
D

dwg1011

Phillip,

Have you considered posting a DetailsView version of the code on your web
site. I am having a devil of a time getting a dependent ddl to work. I have
tried all kinds of variations. My latest version I tried putting the
<asp:sqldatasource> 's underneath the EditTemplate (and InsertTemplates) for
each ddl (1 & 2), but ASP.net is complaining that the control can not be
found. Any help would be greatly appreciated.

David

Phillip Williams said:
You are quite welcome, Karl-Inge. I just managed to put a demo of the
solution I proposed below, with the complete source code, at this link:
http://www.webswapp.com/demos/formView1.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Karl-Inge Reknes said:
Thanks Phillip.

Karl-Inge

Phillip Williams said:
I missed to note that in the solution described below I have used a label
that was 2-way databound to the City instead of the dropdownlist. The label
was styled as hidden. Its purpose is to keep the number of e.NewValues to
the same as if I had the dropdownlist 2-way databound.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

Hi Karl-Inge,

I met the same situation in using dependent dropdownlist within the
EditItemTemplate where 2-way databinding is attempted. The solution is to
remove the 2-way databinding from the dependent dropdownlist and replace it
with customized code during processing the ItemUpdating event.

For example if one had 2 dropdownlists where one had the country and the
other had the City; where the City dropdownlist re-populate every time the
Country selection is changed, then upon ItemUpdating I would do something
like this:
void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
string strCity=
((DropDownList))((FormView)sender).FindControl("ddlCity")).SelectedValue;
e.NewValues[1] = strCity; //assuming the second value being updated is
the City
e.Cancel = false; //this would confirm that the update should continue
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

I have a page with a formview control who datasource is a objectdatasource.
In edit mode template I have tree dropdownlist; Year, Month and Day. Each
dropdownlist i populated from an objectdatasource object and is bind to
column in the formview control objectdatasource. The objectdatasource object
for dropdownlist Day have 2 arguments; Year and Month. The dropdownlist day
is populated with correct number of days for that month and year.

When changing Year or Month this error appear:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

If I remove the binding for dropdownlist Day the error doesn’t appear, but
then I not able to save the Day Column

Is there anybody who can help me?

Karl-Inge Reknes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top