Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IDs the same in header and footer of GridView

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I thought IDs had to be unique on a web page.

DotNet, adds a number at the end of IDs in a GridView row when the Grid is rendered so you will have unique IDs. But it doesn't do that for Headers and Footers (and the yet the page works fine).

If you have something like:

Code:
<asp:TemplateField ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Middle"
    ItemStyle-Width="80px">
    <HeaderTemplate>
        <asp:Label ID="lblQuantityTotal" Text="" runat="server"></asp:Label>
    </HeaderTemplate>
    <FooterTemplate>
        <asp:Label ID="lblQuantityTotal" runat="server"></asp:Label>
    </FooterTemplate>
</asp:TemplateField>

The rendered code may be:
At the top of the Grid
Code:
</th><th align="center" scope="col" style="border-color:Black;border-width:2px;border-style:solid;font-weight:bold;">
<span id="[b]MainPlaceHolder_mGridView_lblOrderQuantityTotal[/b]">291</span>

And at the bottom of the Grid
Code:
</td><td align="center" style="border-color:Black;border-width:2px;border-style:solid;font-weight:bold;">
<span id="[b]MainPlaceHolder_mGridView_lblOrderQuantityTotal[/b]">291</span>

the ID's for the span are identical, how can that be???

Thanks,

Tom
 
They are in different child controls. This is why you have to do a "FindInHeader" or a "FindInFooter" to get at the controls.
The ids must be unique among controls IN THE SAME container.
In addition, if you look at the rendered HTML you will note that they get a different Client ID, that is basically the control tree down to the control.

Lodlaiden

You've got questions and source code. We want both!
There's a whole lot of Irish in that one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top