Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old November 23rd, 2005, 04:12 AM
Frits van Soldt
Guest
 
Posts: n/a
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.
  #2  
Old November 23rd, 2005, 04:12 AM
Phillip Williams
Guest
 
Posts: n/a

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


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:
[color=blue]
> 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.[/color]
  #3  
Old November 23rd, 2005, 04:13 AM
Frits van Soldt
Guest
 
Posts: n/a

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


That's brilliant! Thanks for asnwering so quickly.

"Phillip Williams" wrote:
[color=blue]
> 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:
>[color=green]
> > 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.[/color][/color]
  #4  
Old November 23rd, 2005, 04:13 AM
Phillip Williams
Guest
 
Posts: n/a

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


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).FindContro l("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:
[color=blue]
> That's brilliant! Thanks for asnwering so quickly.
>
> "Phillip Williams" wrote:
>[color=green]
> > 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:
> >[color=darkred]
> > > 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.[/color][/color][/color]
  #5  
Old November 23rd, 2005, 07:15 AM
Frits van Soldt
Guest
 
Posts: n/a

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


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:
[color=blue]
> 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).FindContro l("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:
>[color=green]
> > That's brilliant! Thanks for asnwering so quickly.
> >
> > "Phillip Williams" wrote:
> >[color=darkred]
> > > 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.[/color][/color][/color]
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
DetailsView and template fields studio60podcast@gmail.com answers 7 August 7th, 2006 09:45 PM
ASP:Table Problems clickon answers 2 July 17th, 2006 04:35 PM
Interdependent DropDownLists (with declarative data binding) Timm answers 9 November 19th, 2005 11:58 PM
DetailsView: Change TemplateField properties dynamically (vb) sck10 answers 2 November 19th, 2005 10:55 PM