add display.none to a listview on page_load
I have a listview and want to change its style to di开发者_开发百科splay:none on pageload event. I don't want to set visible=false because I want the element available to javascript code on client side. I am trying this one but with no luck. The div is rendered and is visible.
CategoriesDataList.Style.Add(HtmlTextWriterStyle.Display,"none");
The html is:
<asp:ListView ID="CategoriesDataList" runat="server" DataSourceID="SqlCategories"
OnItemDataBound="CategoriesDataList_Databound" ItemPlaceholderID="categoriesPlaceh">
<LayoutTemplate>
<div id="questionnaire"> ...
<asp:PlaceHolder ID="categoriesPlaceh" runat="server"></asp:PlaceHolder>
...</div>
</LayoutTemplate>
<ItemTemplate> ...
Can you not just add the style="display:none;"
to the server tag? This generally works for me, the server tags normally just convert the extra attributes across.
<asp:ListView ID="MyListView" runat="Server" style="display:none;" />
ok I did it by adding a runat="server" to the div inside the LayoutTemplate and then using FindControl in code behind to change its style. I saw that actually this was the first element that was rendered and not a div with the listview id as I was initially expecting
精彩评论