|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ASP.NET Repeater Control - Hide a <div> ???In my repeater control I have a <div> that is set to run at the server with the intention that I can hide it based on certain criteria. I'm able to do this OK but I'm not sure I have the most efficent method. Heres what I have so far (simplified of course!). Does anybody know a better way????? In the aspx... <asp:Repeater ID="rptTwoSpecials" runat="server"> <ItemTemplate> <div id="co2" runat="server">CO2/km - <%# DataBinder.Eval(Container.DataItem,"co2") %></div> </ItemTemplate> </asp:Repeater> An the code behind (Page_Load event)... foreach (RepeaterItem rptTemp in rptTwoSpecials.Items) { ((HtmlGenericControl)rptTemp.FindControl("co2")).Visible = false; } Thanks guys! Hi there Pete,
First, post all strictly ASP.NET questions to ASP.NET newsgroup. Second, what you're doing is OK but if criteria are known during data binding process you can also handle itemdatabound event: protected void rptTwoSpecials_ItemDataBound(object sender, RepeaterItemEventArgs e) { RepeaterItem item = e.Item; if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { Control panel = item.FindControl("co2"); if (panel != null) panel.Visible = criteriaAreMet; } } -- Show quoteMilosz "sfx_p***@hotmail.com" wrote: > Hi All, > > In my repeater control I have a <div> that is set to run at the server > with the intention that I can hide it based on certain criteria. > > I'm able to do this OK but I'm not sure I have the most efficent > method. Heres what I have so far (simplified of course!). Does > anybody know a better way????? > > In the aspx... > > <asp:Repeater ID="rptTwoSpecials" runat="server"> > <ItemTemplate> > <div id="co2" runat="server">CO2/km - <%# > DataBinder.Eval(Container.DataItem,"co2") %></div> > </ItemTemplate> > </asp:Repeater> > > An the code behind (Page_Load event)... > > foreach (RepeaterItem rptTemp in rptTwoSpecials.Items) > { > ((HtmlGenericControl)rptTemp.FindControl("co2")).Visible > = false; > } > > Thanks guys! > > On Feb 24, 6:49 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote: Show quote > Hi there Pete, Sorry about posting in the wrong place! More speed and less haste!> > First, post all strictly ASP.NET questions to ASP.NET newsgroup. Second, > what you're doing is OK but if criteria are known during data binding process > you can also handle itemdatabound event: > > protected void rptTwoSpecials_ItemDataBound(object sender, > RepeaterItemEventArgs e) > { > RepeaterItem item = e.Item; > > if (item.ItemType == ListItemType.Item || > item.ItemType == ListItemType.AlternatingItem) > { > Control panel = item.FindControl("co2"); > if (panel != null) > panel.Visible = criteriaAreMet; > } > > } > > -- > Milosz > > "sfx_p***@hotmail.com" wrote: > > Hi All, > > > In my repeater control I have a <div> that is set to run at the server > > with the intention that I can hide it based on certain criteria. > > > I'm able to do this OK but I'm not sure I have the most efficent > > method. Heres what I have so far (simplified of course!). Does > > anybody know a better way????? > > > In the aspx... > > > <asp:Repeater ID="rptTwoSpecials" runat="server"> > > <ItemTemplate> > > <div id="co2" runat="server">CO2/km - <%# > > DataBinder.Eval(Container.DataItem,"co2") %></div> > > </ItemTemplate> > > </asp:Repeater> > > > An the code behind (Page_Load event)... > > > foreach (RepeaterItem rptTemp in rptTwoSpecials.Items) > > { > > ((HtmlGenericControl)rptTemp.FindControl("co2")).Visible > > = false; > > } > > > Thanks guys! Thanks, I looked up the event you pointed out, makes more sense to put it there your right :) |
|||||||||||||||||||||||