How to access control in edititemtemplate of detailsview? (ASP 2.0

Discussion in 'ASP .Net' started by =?Utf-8?B?RnJpdHMgdmFuIFNvbGR0?=, Nov 22, 2005.

  1. Hello, I hope somebody can help me with this!
    I have 2 listboxes in the edititemtemplate of a detailsview. In the
    databound event of the detailsview I would like to fill the listboxes
    programmatically (not through databinding). If I use
    detailsview.findcontrol(controlname) then an empty object is returned. How
    can I address these controls?
    Thank you for your time.
    =?Utf-8?B?RnJpdHMgdmFuIFNvbGR0?=, Nov 22, 2005
    #1
    1. Advertising

  2. Hi Frits,

    In the dropdownlist within the DetailsView's TemplateField add OnDatabinding
    = "DropDownList1_DataBinding" and in the CodeBehind add
    protected void DropDownList1_DataBinding(object sender, EventsArgs e)
    {
    // do something
    }
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Frits van Soldt" wrote:

    > Hello, I hope somebody can help me with this!
    > I have 2 listboxes in the edititemtemplate of a detailsview. In the
    > databound event of the detailsview I would like to fill the listboxes
    > programmatically (not through databinding). If I use
    > detailsview.findcontrol(controlname) then an empty object is returned. How
    > can I address these controls?
    > Thank you for your time.
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Nov 22, 2005
    #2
    1. Advertising

  3. RE: How to access control in edititemtemplate of detailsview? (ASP

    That's brilliant! Thanks for asnwering so quickly.

    "Phillip Williams" wrote:

    > Hi Frits,
    >
    > In the dropdownlist within the DetailsView's TemplateField add OnDatabinding
    > = "DropDownList1_DataBinding" and in the CodeBehind add
    > protected void DropDownList1_DataBinding(object sender, EventsArgs e)
    > {
    > // do something
    > }
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Frits van Soldt" wrote:
    >
    > > Hello, I hope somebody can help me with this!
    > > I have 2 listboxes in the edititemtemplate of a detailsview. In the
    > > databound event of the detailsview I would like to fill the listboxes
    > > programmatically (not through databinding). If I use
    > > detailsview.findcontrol(controlname) then an empty object is returned. How
    > > can I address these controls?
    > > Thank you for your time.
    =?Utf-8?B?RnJpdHMgdmFuIFNvbGR0?=, Nov 22, 2005
    #3
  4. RE: How to access control in edititemtemplate of detailsview? (ASP

    You are welcome Frits.

    I might also add that the reason you could not find the control upon
    databinding is that it was not created yet. If you wanted to do it the way
    you tried then you should use the DetailsVeiw.DataBound event instead, e.g,
    DetailsView.DataBound += new EventHandler(DetailsView1_DataBound);

    and then

    void DetailsView1_DataBound(object sender, EventArgs e)
    {
    if(((DetailsView)sender).CurrentMode== DetailsViewMode.Edit)
    {
    DropDownList
    ddl=(DropDownList)((DetailsView)sender).FindControl("DropDownList1");
    if (ddl1 !=null) //you found the dropdownlist
    {
    //execute statements to add the desired data to it
    }
    }

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


    "Frits van Soldt" wrote:

    > That's brilliant! Thanks for asnwering so quickly.
    >
    > "Phillip Williams" wrote:
    >
    > > Hi Frits,
    > >
    > > In the dropdownlist within the DetailsView's TemplateField add OnDatabinding
    > > = "DropDownList1_DataBinding" and in the CodeBehind add
    > > protected void DropDownList1_DataBinding(object sender, EventsArgs e)
    > > {
    > > // do something
    > > }
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "Frits van Soldt" wrote:
    > >
    > > > Hello, I hope somebody can help me with this!
    > > > I have 2 listboxes in the edititemtemplate of a detailsview. In the
    > > > databound event of the detailsview I would like to fill the listboxes
    > > > programmatically (not through databinding). If I use
    > > > detailsview.findcontrol(controlname) then an empty object is returned. How
    > > > can I address these controls?
    > > > Thank you for your time.
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Nov 22, 2005
    #4
  5. RE: How to access control in edititemtemplate of detailsview? (ASP

    Thank you, Phillip!
    I tried the databound event earlier, but unfortunately it seems that
    controls in the edititemtemplate are not created at that time. Only when the
    detailsview is actually in edit mode.
    Cheers,
    Frits

    "Phillip Williams" wrote:

    > You are welcome Frits.
    >
    > I might also add that the reason you could not find the control upon
    > databinding is that it was not created yet. If you wanted to do it the way
    > you tried then you should use the DetailsVeiw.DataBound event instead, e.g,
    > DetailsView.DataBound += new EventHandler(DetailsView1_DataBound);
    >
    > and then
    >
    > void DetailsView1_DataBound(object sender, EventArgs e)
    > {
    > if(((DetailsView)sender).CurrentMode== DetailsViewMode.Edit)
    > {
    > DropDownList
    > ddl=(DropDownList)((DetailsView)sender).FindControl("DropDownList1");
    > if (ddl1 !=null) //you found the dropdownlist
    > {
    > //execute statements to add the desired data to it
    > }
    > }
    >
    > }
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Frits van Soldt" wrote:
    >
    > > That's brilliant! Thanks for asnwering so quickly.
    > >
    > > "Phillip Williams" wrote:
    > >
    > > > Hi Frits,
    > > >
    > > > In the dropdownlist within the DetailsView's TemplateField add OnDatabinding
    > > > = "DropDownList1_DataBinding" and in the CodeBehind add
    > > > protected void DropDownList1_DataBinding(object sender, EventsArgs e)
    > > > {
    > > > // do something
    > > > }
    > > > --
    > > > HTH,
    > > > Phillip Williams
    > > > http://www.societopia.net
    > > > http://www.webswapp.com
    > > >
    > > >
    > > > "Frits van Soldt" wrote:
    > > >
    > > > > Hello, I hope somebody can help me with this!
    > > > > I have 2 listboxes in the edititemtemplate of a detailsview. In the
    > > > > databound event of the detailsview I would like to fill the listboxes
    > > > > programmatically (not through databinding). If I use
    > > > > detailsview.findcontrol(controlname) then an empty object is returned. How
    > > > > can I address these controls?
    > > > > Thank you for your time.
    =?Utf-8?B?RnJpdHMgdmFuIFNvbGR0?=, Nov 23, 2005
    #5
  6. =?Utf-8?B?RnJpdHMgdmFuIFNvbGR0?=

    ashishbuddha

    Joined:
    Jul 18, 2006
    Messages:
    2
    bindind data in drop dropdownlist in edit mode

    hello frits and philip,


    i am having the same problem. i need to user to pick from drop down list when in edit mode. I am not able to bind it. When i write the codebehind detailsview_databinding, i am getting an error saying the dropperson (which is dropdowmlist id in edit itemtemplate) is not declared. Can u please help me how do i get around this issue.

    Thx
    ashish
    ashishbuddha, Jul 19, 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. K B
    Replies:
    0
    Views:
    2,000
  2. K B
    Replies:
    0
    Views:
    3,467
  3. Trevor Bezotte

    DetailsView EditItemTemplate DropdownList Update Problem

    Trevor Bezotte, Dec 1, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    9
    Views:
    313
    Steven Cheng[MSFT]
    Dec 8, 2005
  4. Feege
    Replies:
    0
    Views:
    436
    Feege
    Dec 20, 2005
  5. MikeR
    Replies:
    0
    Views:
    193
    MikeR
    Aug 25, 2006
Loading...

Share This Page