FindControl in a Datalist

A

Adam Billmeier

Problem:
I am trying to use FindControl to grab a dropdownlist that is in the
EditItemTemplate of a Datalist and then Bind it to a dataset. I also then
need to put the correct values in all of the text boxes in the
EditItemTemplate.

I have set the EditItemIndex for the Datalist to -1, and then bound the
Datalist. I then want to Bind the DropDown, and populate the values.

All attempts to use FindControl on the control return "Nothing"

Any assistance is appreciated.
 
T

Tom Bray

Adam,

I am pretty sure you need to use the onITemCreated event after you have
bound your datalist. In this event you can bind you dropdownlist as you go
each item gets created. Does that sound right?
 
R

Rick Spiewak

If you're looking for a dropdownlist that's in the EditItemTemplate, you'll
need a to do so when the value for EditItemIndex is other than -1! Then, you
can look for the case of e.item is edit item type in the itemdatabound
event, and use .findcontrol on the item itself to find your dropdownlist,
and bind it.
 
A

Adam Billmeier

Ok, just to be clear, I want to bind a datalist and populate controls when
the datalist is in edit mode. I want to display a couple dropdown and some
textboxes that would have been straight labels in the non-edit view.

It is now time to update the data, so the new controls are needed.
 
R

Rick Spiewak

Yes. Make your column(s) templated, and add the dropdowns and textboxes to
the edit item template. Set the databindings of these controls as you like.
If you want the dropdowns to display the value from the label, you'll
probably need some code in the itemdatabound event. Use select case for the
edit item type to operate only on this item, then use .Findcontrol to find
it by ID, and set the selectedindex to the item which matches the value from
your data source at the .datasetindex of the item.
 
A

Adam Billmeier

Ok.
I have all of that figured out now, and I thank you for your help. I have
pretty much the same problem now however when I want to pass the
changed/updated fields back to the database.

In my head, I want to click the save button. Then in ItemCommand (if save
was clicked) stick each of the new values into a sqlcommand with parameters
and pass them off to the stored procedure.

The problem once again is grabbing the controls and extracting their values.
I would like to use FindControl, but this still is returning nothing in the
ItemCommand event.

Help?
 
J

Johnny Fugazzi

Got it working.
Thanks

Rick Spiewak said:
Yes. Make your column(s) templated, and add the dropdowns and textboxes to
the edit item template. Set the databindings of these controls as you like.
If you want the dropdowns to display the value from the label, you'll
probably need some code in the itemdatabound event. Use select case for the
edit item type to operate only on this item, then use .Findcontrol to find
it by ID, and set the selectedindex to the item which matches the value from
your data source at the .datasetindex of the item.
 
R

Rick Spiewak

Are you checking for the edititem?
Adam Billmeier said:
Ok.
I have all of that figured out now, and I thank you for your help. I have
pretty much the same problem now however when I want to pass the
changed/updated fields back to the database.

In my head, I want to click the save button. Then in ItemCommand (if save
was clicked) stick each of the new values into a sqlcommand with parameters
and pass them off to the stored procedure.

The problem once again is grabbing the controls and extracting their values.
I would like to use FindControl, but this still is returning nothing in the
ItemCommand event.

Help?
 

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

Top