Home All Groups Group Topic Archive Search About
Author
3 Dec 2005 7:52 PM
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

Author
5 Dec 2005 9:17 PM
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
}
Show quoteHide quote
"Karl-Inge Reknes" wrote:

> 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
>
Author
6 Dec 2005 1:13 AM
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.
Show quoteHide quote
"Phillip Williams" wrote:

> 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" wrote:
>
> > 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
> >
Author
6 Dec 2005 8:36 AM
Karl-Inge Reknes
Thanks Phillip.

Karl-Inge

Show quoteHide quote
"Phillip Williams" wrote:

> 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" wrote:
>
> > 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" wrote:
> >
> > > 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
> > >
Author
6 Dec 2005 9:06 AM
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

Show quoteHide quote
"Karl-Inge Reknes" wrote:

> Thanks Phillip.
>
> Karl-Inge
>
> "Phillip Williams" wrote:
>
> > 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" wrote:
> >
> > > 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" wrote:
> > >
> > > > 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
> > > >
Author
9 Apr 2006 7:40 AM
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

Show quoteHide quote
"Phillip Williams" wrote:

> 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" wrote:
>
> > Thanks Phillip.
> >
> > Karl-Inge
> >
> > "Phillip Williams" wrote:
> >
> > > 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" wrote:
> > >
> > > > 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" wrote:
> > > >
> > > > > 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
> > > > >