我已经完成了Header,Item和Footer但没有使用Bootstrap 3.0的Pager
您能否指导我如何在ASP.NET Gridview寻呼机样式中实现Bootstrap分页?
请帮忙!
其他信息:::
这是我到目前为止通过添加CssClass所做的。表格显示完美,并应用了Bootstrap样式。
<div class="table-responsive">
<asp:GridView ID="grdSearchAgreement" runat="server" CssClass="table table-hover"
GridLines="None" AllowPaging="true" PageSize="2">
</asp:GridView>
</div>
这是从ASP.NET GridView生成的Paging样式。它是表结构tr td。
<tr>
<td colspan="7"><table>
<tr>
<td><span>1</span></td><td><a href="javascript:__doPostBack('ctl00$body$grdSearchAgreement','Page$2')">2</a></td><td><a href="javascript:__doPostBack('ctl00$body$grdSearchAgreement','Page$3')">3</a></td>
</tr>
</table></td>
</tr>
但请参阅Bootstrap 3.0分页文档。风格只适用于ul li。 https://getbootstrap.com/docs/3.3/components/#pagination
<ul class="pagination">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
如何将从gridview生成的tr td寻呼机更改为ul li ??
答案 0 :(得分:39)
我知道这是旧的,但我找到了一些东西,这是一种简单快捷的css风格
https://sufiawan.wordpress.com/2014/09/26/asp-net-use-bootstrap-pagination-on-gridview/
我希望它会在某个时候拯救某人。
更新
*如果链接已关闭:
添加CSS
.pagination-ys {
/*display: inline-block;*/
padding-left: 0;
margin: 20px 0;
border-radius: 4px;
}
.pagination-ys table > tbody > tr > td {
display: inline;
}
.pagination-ys table > tbody > tr > td > a,
.pagination-ys table > tbody > tr > td > span {
position: relative;
float: left;
padding: 8px 12px;
line-height: 1.42857143;
text-decoration: none;
color: #dd4814;
background-color: #ffffff;
border: 1px solid #dddddd;
margin-left: -1px;
}
.pagination-ys table > tbody > tr > td > span {
position: relative;
float: left;
padding: 8px 12px;
line-height: 1.42857143;
text-decoration: none;
margin-left: -1px;
z-index: 2;
color: #aea79f;
background-color: #f5f5f5;
border-color: #dddddd;
cursor: default;
}
.pagination-ys table > tbody > tr > td:first-child > a,
.pagination-ys table > tbody > tr > td:first-child > span {
margin-left: 0;
border-bottom-left-radius: 4px;
border-top-left-radius: 4px;
}
.pagination-ys table > tbody > tr > td:last-child > a,
.pagination-ys table > tbody > tr > td:last-child > span {
border-bottom-right-radius: 4px;
border-top-right-radius: 4px;
}
.pagination-ys table > tbody > tr > td > a:hover,
.pagination-ys table > tbody > tr > td > span:hover,
.pagination-ys table > tbody > tr > td > a:focus,
.pagination-ys table > tbody > tr > td > span:focus {
color: #97310e;
background-color: #eeeeee;
border-color: #dddddd;
}
只需在grd中使用
<PagerStyle CssClass="pagination-ys" />
答案 1 :(得分:8)
我的回答取自iYazee6之前的回答 这里新增的是增强分页的CSS布局,实现它然后显示结果。
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" CssClass="table table-striped table-hover" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="10">
<PagerStyle HorizontalAlign = "Center" CssClass = "GridPager" />
...
css代码:
.GridPager a,
.GridPager span {
display: inline-block;
padding: 0px 9px;
margin-right: 4px;
border-radius: 3px;
border: solid 1px #c0c0c0;
background: #e9e9e9;
box-shadow: inset 0px 1px 0px rgba(255,255,255, .8), 0px 1px 3px rgba(0,0,0, .1);
font-size: .875em;
font-weight: bold;
text-decoration: none;
color: #717171;
text-shadow: 0px 1px 0px rgba(255,255,255, 1);
}
.GridPager a {
background-color: #f5f5f5;
color: #969696;
border: 1px solid #969696;
}
.GridPager span {
background: #616161;
box-shadow: inset 0px 0px 8px rgba(0,0,0, .5), 0px 1px 0px rgba(255,255,255, .8);
color: #f0f0f0;
text-shadow: 0px 0px 3px rgba(0,0,0, .5);
border: 1px solid #3AC0F2;
}
结果是:
答案 2 :(得分:1)
您可以为GridView控件提供PagerTemplate。 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pagertemplate.aspx
答案 3 :(得分:1)
Bootsrap Pagination是静态的。您必须使其动态化才能将其添加到gridview中,以便根据gridview中的记录数生成寻呼机元素。您需要编写一些jquery代码才能使其动态化。最好的方法是使用大量可用的jquery插件,例如Bootpag。
以下是how to use Bootstrap pagination in ASP.NET GridView的典型示例。
答案 4 :(得分:0)
iYazee6的结果导致我的网格显示问题。它只占用网格的第一列来保存寻呼机,即使对于6列网格,html也是colspan =“6”。我无法确定原因。 GridPager css的增强解决方案非常棒。 我添加了一些更多的CSS来使用它像Bootstrap,即GridPager-info或GridPager-Danger或GridPager-Success来相应地改变颜色。
CSS代码段是:
/***** GridPager-Danger *****/
.GridPager-Danger a,
.GridPager-Danger span {
border: solid 1px #C60C30;
background: #e9e9e9;
color: #717171;
}
.GridPager-Danger a {
background-color: #f5f5f5;
color: #C60C30;
border: 1px solid #C60C30;
}
.GridPager-Danger a:hover {
background-color: #C60C30;
color: #f5f5f5;
}
.GridPager-Danger span {
background: #C60C30;
color: #f0f0f0;
}
/***** GridPager-Success *****/
.GridPager-Success a,
.GridPager-Success span {
border: solid 1px #3c763d;
background: #eeffcc;
color: #717171;
}
.GridPager-Success a {
background-color: #eeffcc;
color: #3c763d;
border: 1px solid #3c763d;
}
.GridPager-Success a:hover {
background-color: #3c763d;
color: #f5f5f5;
}
.GridPager-Success span {
background: #3c763d;
color: #f0f0f0;
}
你只需要将这个css与GridPager css文件中的GridPager css一起复制并将此代码添加到你的html中
<PagerStyle HorizontalAlign = "Center" CssClass="GridPager GridPager-Info" />
OR
<PagerStyle HorizontalAlign = "Center" CssClass="GridPager GridPager-Success" />
OR
<PagerStyle HorizontalAlign = "Center" CssClass="GridPager GridPager-Danger" />
它可能会帮助使用Bootstrap的人
答案 5 :(得分:0)
这适用于bootstrap 4 rtl
添加PagerStyle-CssClass =“bs4-aspnet-pager”
/*bs4-aspnet-pager*/
.bs4-aspnet-pager a,
.bs4-aspnet-pager span {
position: relative;
float: right;
padding: 6px 12px;
margin-right: -1px;
line-height: 1.42857143;
color: ##007bff;
text-decoration: none;
background-color: #fff;
border: 1px solid #ddd;
}
.bs4-aspnet-pager span {
z-index: 3;
color: #fff;
cursor: default;
background-color: #007bff;
border-color: #007bff;
}
.bs4-aspnet-pager tr > td:first-child > a,
.bs4-aspnet-pager tr > td:first-child > span {
margin-right: 0;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.bs4-aspnet-pager tr > td:last-child > a,
.bs4-aspnet-pager tr > td:last-child > span {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.bs4-aspnet-pager a:hover,
.bs4-aspnet-pager span:hover,
.bs4-aspnet-pager a:focus,
.bs4-aspnet-pager span:focus {
z-index: 2;
color: #23527c;
background-color: #eee;
border-color: #ddd;
}
.bs4-aspnet-pager td {
padding: 0;
}
/*end bs4-aspnet-pager */
答案 6 :(得分:0)
以Yusuf Setiawan博客上面的iYazee6帖子为基础。
我将a分开:悬停和跨度:悬停并增加填充宽度以使其对鼠标悬停起作用。原始填充:8px 12px。也使字体变粗。
.pagination-ys table > tbody > tr > td > a:hover,
.pagination-ys table > tbody > tr > td > span:hover {
padding: 8px 16px;
color: #97310e;
font-weight: bold;
background-color: #eeeeee;
border-color: #dddddd;
}
答案 7 :(得分:0)
只需稍微自定义this question中的答案,您就会拥有不错的GridView分页器,该分页器支持任何Twitter Bootstrap CSS主题。
GridView模板:
<asp:GridView ... AllowPaging="true" PageSize="10">
...
<PagerStyle HorizontalAlign="Center" />
<PagerTemplate>
<ul class="pagination">
<asp:Repeater ID="Pager" ItemType="System.Int32" SelectMethod="GetPages" runat="server">
<ItemTemplate>
<li class='<%#((int)Item == this.GridView.PageIndex+1)? "active" : "" %>'>
<asp:LinkButton CommandName="Page" CommandArgument="<%# Item %>"
Text="<%# Item %>" runat="server" OnClick="PageIndexChanging" />
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</PagerTemplate>
</asp:GridView>
服务器端代码:
public IEnumerable<int> GetPages()
{
return Enumerable.Range(1, GridView.PageCount);
}
protected void PageIndexChanging(object sender, EventArgs e)
{
LinkButton pageLink = (LinkButton)sender;
GridView.PageIndex = Int32.Parse(pageLink.CommandArgument) - 1;
BindDataToGridView();
}
答案 8 :(得分:0)
HTML标记由ASP.Net GridView组成。对于GridView,我已经使用AllowPaging属性启用了分页,并且还对OnPageIndexChanging事件进行了指定。
将GridView与罗斯文数据库的“客户”表中的记录绑定的代码。
要为GridView Pager设置样式,您需要遵循以下步骤。
接下来,您需要使用PagerStyle-CssClass属性将Pager CSS类分配给页面,如下所示。
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
runat="server" AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging">
<Columns>
<asp:BoundField DataField="ContactName" HeaderText="Contact Name" ItemStyle-Width="150px" />
<asp:BoundField DataField="City" HeaderText="City" ItemStyle-Width="100px" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="100px" />
</Columns>
<PagerStyle HorizontalAlign = "Right" CssClass = "GridPager" />
</asp:GridView>
<PagerStyle HorizontalAlign = "Right" CssClass = "GridPager" />
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.GridPager a, .GridPager span
{
display: block;
height: 15px;
width: 15px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
.GridPager a
{
background-color: #f5f5f5;
color: #969696;
border: 1px solid #969696;
}
.GridPager span
{
background-color: #A1DCF2;
color: #000;
border: 1px solid #3AC0F2;
}
</style>