Formview DropDownList bug??

Discussion in 'ASP .Net Web Controls' started by Karl-Inge Reknes, Dec 3, 2005.

  1. 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
     
    Karl-Inge Reknes, Dec 3, 2005
    #1
    1. Advertising

  2. 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
    >
     
    Phillip Williams, Dec 5, 2005
    #2
    1. Advertising

  3. 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
    > >
     
    Phillip Williams, Dec 6, 2005
    #3
  4. 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
    > > >
     
    Karl-Inge Reknes, Dec 6, 2005
    #4
  5. 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
    > > > >
     
    Phillip Williams, Dec 6, 2005
    #5
  6. Karl-Inge Reknes

    dwg1011 Guest

    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" 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
    > > > > >
     
    dwg1011, Apr 9, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RlI=?=

    Using DropDownList control in FormView

    =?Utf-8?B?RlI=?=, Dec 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    400
    =?Utf-8?B?RlI=?=
    Dec 13, 2004
  2. Rabbit
    Replies:
    0
    Views:
    1,718
    Rabbit
    Mar 20, 2006
  3. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    558
    Chris
    May 19, 2007
  4. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    673
    David Thielen
    Jun 16, 2006
  5. Lagrange
    Replies:
    1
    Views:
    569
    Lagrange
    Jan 17, 2009
Loading...

Share This Page