DataGrid appending to my ItemTemplate IDs?

J

Jim Bancroft

Hi everyone,

I'm using a DataGrid on one of my web pages and within it I have an
ItemTemplate containing a DropDownList. The relevant section looks like
this:

<asp:datagrid id="DataGrid1" runat="server">
........
<Columns>
<asp:TemplateColumn HeaderText="Division">
<ItemTemplate>
<asp:DropDownList runat="server" id="Dropdownlist1"
DataTextField="Name" DataValueField="DepartmentID" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
........

In the final HTML output my DropDownList items wind up as <select> tags
with names like "DataGrid1:_ctl2:Dropdownlist1." Even if I change the ID
values in my code-behind file (looping through all the DropDowns in the
DataGrid) the DataGrid still prepends to the ID-- the final IDs now read
something like "DataGrid1:_ctl2:DropDown3"

I'm not sure how to handle this. I read the values of these DropDowns
after posting the page, but if the DataGrid adds its own information to the
ID values then I'm likely to miss them or get the names wrong when I call
Request.Form[...]. And what if I add, say, a label to my DataGrid? Would
it change the prepended ID text on the other controls embedded in the
DataGrid?

I'd like to make sure my embedded controls at least consistently named.
Is it guaranteed that the DataGrids will always prepend the same information
to the IDs (<DataGrid Name>:_ctl<count>), or am I going to get in trouble
with that assumption?
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top