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
ropDownList 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
ropdownlist1." 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
ropDown3"
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?
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
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
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
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?