Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com
I've created the GridView with templates like the following:
       <asp:TemplateField SortExpression="Date1">

            <AlternatingItemTemplate>

                <asp:CheckBox ID="chkSelected" runat="server" />

            </AlternatingItemTemplate>

        </asp:TemplateField>

        <asp:TemplateField SortExpression="Date2">

            <AlternatingItemTemplate>

                <asp:CheckBox ID="chkSelected" runat="server" />

            </AlternatingItemTemplate>

        </asp:TemplateField>

On runtime it cause the error:
Message : Multiple controls with the same ID 'chkSelected' were found. FindControl requires that controls have unique IDs.
Type : System.Web.HttpException, System.Web, Version=
2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Message : Multiple controls with the same ID 'chkSelected' were found. FindControl requires that controls have unique IDs.
Source : System.Web
ErrorCode : -2147467259
Stack Trace : at System.Web.UI.Control.FillNamedControlsTable(Control namingContainer, ControlCollection controls)
at System.Web.UI.Control.FillNamedControlsTable(Control namingContainer, ControlCollection controls)
at System.Web.UI.Control.EnsureNamedControlsTable()
at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
at System.Web.UI.Page.FindControl(String id)
at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The problem explained on forum "GridViewRow is the naming container in GridView, not individual TableCell.
 
I had to use Dynamic Template columns based on  page http://www.webswapp.com/codesamples/viewsource.aspx?file=~/codesamples/aspnet20/itemplate/checkboxtemplate.cs
Note that in that example the CheckBoxTemplate class declared as implemented INamingContainer.
It causes expectation, that generated cell is naming container, which is not correct.
Because template is not derived from Control, specifying INamingContainer interface has no effect and should be removed.
 
Similar templates are described in
Posted on Monday, May 5, 2008 11:21 PM ASP.NET | Back to top


Comments on this post: Controls with the same name in GridView Templates

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net