简体   繁体   English

如何将CSS样式添加到DataPager

[英]How to add CSS Styles to DataPager

I have a simple question. 我有一个简单的问题。 I have a ListView which I have added a DataPager control to. 我有一个ListView,我已经向其中添加了DataPager控件。

At present the DataPager is just plain numeric based. 目前,DataPager只是基于纯数字的。 Just wondering, is it possible to add CSS styles to the numeric numbers IE have a 1px solid border around each number ect. 只是想知道,是否可以将CSS样式添加到数字IE中,每个数字ect周围都有1px的实心边框。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Insert NumericButtonCssClass to the NumericPagerField 将NumericButtonCssClass插入NumericPagerField

in my example i call it datapagerStyle 在我的示例中,我将其称为datapagerStyle

       <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="20">
    <Fields>
        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="False" ShowNextPageButton="False"
            ShowPreviousPageButton="False" />
           <asp:NumericPagerField NumericButtonCssClass="datapagerStyle" />
        <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="False" ShowNextPageButton="False"
            ShowPreviousPageButton="False" />
    </Fields>
</asp:DataPager>

and then in the stylesheet you make 然后在样式表中

.datapagerStyle
{
    color:black;
    border: 1px solid black;
}

I think this will solve your problem 我认为这可以解决您的问题

    <asp:DataPager ID="DataPager1" runat="server" PageSize="6" OnPreRender="DataPager1_PreRender">
                                <Fields>
                                    <asp:NumericPagerField ButtonCount="5" NumericButtonCssClass="numeric_button" CurrentPageLabelCssClass="current_page" NextPreviousButtonCssClass="next_button"/>
                                    <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" 
                                        ShowNextPageButton="false" ShowPreviousPageButton="False" ButtonCssClass="last_button" />
                                </Fields>
                            </asp:DataPager>


   <style type="text/css">
   .numeric_button{background-color:#384B69;color:#FFFFFF;font-family:Arial;font-weight:bold;padding:2px;  border:none;}
    .current_page{background-color:#09151F;color:#FFFFFF;font-family:Arial;font-weight:bold;padding:2px;}
    .next_button{background-color:#1F3548;color:#FFFFFF;font-family:Arial;font-weight:bold;padding:2px;}
    .last_button{background-color:#1F3548;color:#FFFFFF;font-family:Arial;font-weight:bold;padding:2px;}
   </style>

You can set CssClass for your control I think that can do what you want. 您可以为您的控件设置CssClass,我认为可以做到您想要的。 I don't test it so just an ideal! 我没有测试,所以只是一个理想! Hope this helpfull 4 you! 希望对您有帮助4 CssClass="Pagging" Pagging{ border:1px solid #000; }

I don't know what a DataPager control is. 我不知道什么是DataPager控件。 But if it's some kind of pagination* class, and you want to do something like what's at the bottom of the StackOverflow New Questions page, then yes it is completely doable in CSS. 但是,如果它是某种分页*类,并且您想要执行类似StackOverflow New Questions页面底部的操作,那么是的,它完全可以在CSS中使用。

In most cases, the page numbers are just hyperlinks. 在大多数情况下,页码只是超链接。 So what you can do is find out what class the pagination control uses for the links, and style them the way you want. 因此,您可以做的是找出分页控件用于链接的类,然后按所需的方式对其进行样式设置。 For instance, if the HTML looks something like this: 例如,如果HTML看起来像这样:

<div class="pagination">
    <span class="page_cur">1</span>
    <a href="news.php?page=2" class="page_num">2</a>
    <a href="news.php?page=3" class="page_num">3</a>
    <a href="news.php?page=4" class="page_num">4</a>
    <a href="news.php?page=5" class="page_num">5</a>
    ...
</div>

Then you'll want to include something like this in your CSS: 然后,您需要在CSS中包含以下内容:

<style>
div.pagination > span.page_cur, div.pagination > a.page_num {
   display: block;
   float: left;
   padding: 4px;
}
div.pagination > span.page_cur {
   background-color: #ddd;
   border: 1px solid #ddd;
}
div.pagination > a.page_num {
   background-color: #fff;
   border: 1px solid #e0e0e0;
}
</style>

If you don't know the CSS selectors to use for the pagination numbers, I suggest taking a look at some online references on CSS selectors. 如果您不知道用于分页编号的CSS选择器,建议您查看一些有关CSS选择器的在线参考。 The Firebug plugin for Firefox is also very helpful in identifying layout elements and the styles currently applied to them. Firefox的Firebug插件在识别布局元素和当前应用于它们的样式方面也非常有帮助。

*StackOverflow doesn't like URLs with underscores in them apparently: Pagination * StackOverflow显然不喜欢带有下划线的URL: 分页

As Nguyen Hiep answered, setting a CSSClass to the control might help. 正如Nguyen Hiep回答的那样,将CSSClass设置为控件可能会有所帮助。 Then look at the source code generated by the control. 然后查看该控件生成的源代码。 The reason the CssClass might not be removing the border could be that .NET has the tendency to wrap the generated HTML elements in extra divs or tables (the border might be set on a different element contained in that div) Once you find out which element has the css class, use CSS descendant selector to remove the border. CssClass可能不会删除边框的原因可能是.NET倾向于将生成的HTML元素包装在额外的div或表中(边框可能设置在该div中包含的其他元素上)一旦找到了哪个元素具有css类,请使用CSS后代选择器删除边框。

Because in .NET when it generate a control it automatically add prefix something like: controlID = "data_customer" and became like that ctrl_1_etc_ + data_customer. 因为在.NET中,当它生成控件时,它会自动添加前缀,例如:controlID =“ data_customer”,并变得像ctrl_1_etc_ + data_customer。 So you must write all the long name of this control in CSS file and it work for sure! 因此,您必须在CSS文件中写入此控件的所有长名称,并且它一定可以正常工作! Hope this help you! 希望这对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM