Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Make Code-Behind Reflect Changes To Designer?

0 views
Skip to first unread message

JebBushell

unread,
Dec 14, 2005, 5:25:03 AM12/14/05
to
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.

REMOVE @removeopenmymindremovemetoo.andmenet Karl Seguin

unread,
Dec 14, 2005, 8:40:42 AM12/14/05
to
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

--

MY ASP.Net tutorials
http://www.openmymind.net/

"JebBushell" <jebbushell AT yahoo DOT com> wrote in message
news:E7CF0F5B-5AEA-4967...@microsoft.com...

j3b

unread,
Dec 14, 2005, 3:19:41 PM12/14/05
to
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.

0 new messages