How to Make Code-Behind Reflect Changes To Designer?

G

Guest

I have an existing page, that works, and I'm trying to enhance it by adding a
dropdown in a datagrid. When I add the dropdown, I expect the code-behind
file to be updated by VS. It should be updated to contain a type declaration
for the new dropdown with a variable name that is the same as the id that I
set in the designer.

Do I expect correctly?

Well, it's not happening. And it doesn't matter whether it's an HTML or a
web control. The type declaration is not being generated automatically. If
I add the declaration manually, it fools the compiler but not the runtime.

I think there may be something important here that I do not understand. Can
anyone tell me what I need to read about in order to debug this situation?

Thanks.
 
K

Karl Seguin

There isn't a single instance of the dropdownlist. When you put a control
into a template list, the "normal" declaretive model isn't correct anymore.
If you do:

<itemTemplate>
<asp:dropdownlist id="x" runat="server" />
</itemTemplate>

you can't simply manipulate X like you would any other control. Which "X"
do you want? The one in row1, row2, row3??

Typically, you hook into the grids/list/repeater's ItemDataBound event,
which fires for each row being bound:

e.Item <-- the row being bound. From that, you can access the dropdownlist
via a FindControl

DropDownList x = (DropDownList)e.Item.FindControl("x");

take a look at:
http://openmymind.net/MyArticles.aspx?documentId=8

Karl
 
J

j3b

Thanks Karl.

Here's your answer implemented:

dgPumps.Items[dgPumps.EditItemIndex].Cells[5].Controls.Add(ddlBrand);

where ddlBrand is a local instance of HtmlSelect that has previously
been databound.

Works great. Thanks again.
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top