asp.net datalist - change styling

你。 提交于 2019-12-25 04:53:33

问题


<asp:DataList ID="ItemsList" RepeatDirection="Vertical" runat="server">            
  <ItemTemplate>                  
        <asp:LinkButton 
            ID="SecondLevelItem" runat="server"  CommandName="second" 
            OnCommand="SecondLevelItem_Onclick" CommandArgument="<%# Container.DataItem %>" 
            Text="<%# Container.DataItem %>" >  
        </asp:LinkButton>                                     
    </ItemTemplate>            
 </asp:DataList>

everything works fine. except that I do not have any control over the styling on the items. I mean I have the styling on the datalist externally but I want to add some spacing (vertically) between each item. How do I do tht? Thanks


回答1:


In general, to control style, you can apply the <ItemStyle> tag inside the <asp:DataList>.

You can optionally inject CSS properties into the asp:LinkButton tag, either with the class attribute or directly with style, controlling the height or other CSS properties.

If it's applicable, you can still add a
on the bottom of the template (but this will add a vertical space to the last item too, and I don't know if you want it).

Hope to have been of help.




回答2:


In the code behind databound method for the list, you may be able to add a css class via the attributes collection.

In fact you may be able to that declartively too, just checking now...

eg asp:DataList id="blah" runat="server" ItemStyle-CssClass="someClass"



来源:https://stackoverflow.com/questions/4046531/asp-net-datalist-change-styling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!