asp.net - Find a repeater inside a unordered list inside a master page? -
i have loaded html template master page , bind category database. have used coding.
<ul class="categories"> <li id="categoryitem"> <h4>categories</h4> <ul class="categories" id="categorylist"> <asp:repeater id="repcategories" runat="server"> <headertemplate><ul></headertemplate> <itemtemplate> <li> <asp:hyperlink id="hypercategories" runat="server"><%#eval("categoryname")%></asp:hyperlink> </li> </itemtemplate> <footertemplate></ul></footertemplate> </asp:repeater> </ul> </li>
and try bind repeater database doing coding on master.cs page.
if (!ispostback) { dataset ds = new viewaction().getallproductcategorydata(); repcategories.datasource = ds; repcategories.databind(); }
but showing error
"the name repcategories not exist in current context"
why showing error me solve this. please
the reason code (as-written) isn't working, because repeater nested within 2 other server controls:
<li runat="server">
,<ul class="categories" runat="server" id="categorylist">
.
this means repeater in different "naming container" top-level elements, , isn't directly accessible masterpage's codebehind file.
to fix this, need either
- remove
runat="server"
controls (if don't need access them server side code). allow code work way now. or, - add id
<li>
element, , usefindcontrol
method access nested repeater.
option 2 (we'll assume gave <li>
id of "categoryitem"):
if (!ispostback) { // repeater nested controls first repeater repcategories = (repeater)categoryitem.findcontrol("categorylist").findcontrol("repcategories"); // rest of work dataset ds = new viewaction().getallproductcategorydata(); repcategories.datasource = ds; repcategories.databind(); }
you need use code "get" repeater in place need access in codebehind.
Comments
Post a Comment