我想在分页中实现这种样式,并且数字像CSDN分页那样,点了之后变成红色。:
1 2 3 4 5 6 7 8 9 10 ...   (共 12 页 当前第1页)
我现在用了这段代码
 protected void GridView1_DataBound(object sender, EventArgs e)
    {
        GridViewRow gvRow = this.GridView1.BottomPagerRow;
        Label pagerLBL = new Label();
        pagerLBL.Text = " (共 " + this.GridView1.PageCount.ToString() + " 页      " + "当前第"+ (this.GridView1.PageIndex+1).ToString() +"页)";
        gvRow.Cells[0].Controls.Add(pagerLBL);
    }
只能实行这种样式:
1 2 3 4 5 6 7 8 9 10 ...   
(共 12 页 当前第1页)谢谢各位!!!

解决方案 »

  1.   

    重写RowCreate试试
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (GridView1.AllowPaging && e.Row.RowType == DataControlRowType.Pager)
            {
                TableRow row = ((Table)e.Row.Cells[0].Controls[0]).Rows[0];
                if (row.Cells.Count == 0)
                    return;            TableCell cell = row.Cells[0];            Label pagerLBL = new Label();
                pagerLBL.Text = " (共 " + this.GridView1.PageCount.ToString() + " 页      " + "当前第" + (this.GridView1.PageIndex + 1).ToString() + "页)";            cell.Controls.Add(pagerLBL);
            }
        }
      

  2.   

    cell.Controls.Add(pagerLBL);
    改成
    row.Controls.Add(pagerLBL);试试
      

  3.   

    TableRow row = ((Table)e.Row.Cells[0].Controls[0]).Rows[0];
                if (row.Cells.Count == 0)
                    return;            TableCell cell = row.Cells[row.Cells.Count-1];            Label pagerLBL = new Label();
                pagerLBL.Text = " (共 " + this.GridView1.PageCount.ToString() + " 页      " + "当前第" + (this.GridView1.PageIndex + 1).ToString() + "页)";            cell.Controls.Add(pagerLBL);
      

  4.   

    指定的参数已超出有效值的范围。
    参数名: index 
    我用了这个语句:row.Cells[10].Controls.Add(pagerLBL);
    格式差不多了,1 2 3 4 5 6 7 8 9 10 ... (共 12 页 当前第1页) 
    这样会不会有问题呢,还有颜色的问题可否提示一下呢!!
      

  5.   

    row.Cells中依次是1 2 3 4 5 6 7 8 9 10 ...   
    你把对应页的Cell的Text加上"<font color='red'></font>应该就可以了把
    自己多试试
      

  6.   

    TableCell cell = row.Cells[this.GridView1.PageIndex];
    cell.Text = "<font color='red'>" + cell.Text =+ "</font>"加上这句试试?
      

  7.   

    颜色问题完全可以用css控制:
    加上:
    <style>
            table tr td table tr td span { color:red; }
        </style>
    就可以了
      

  8.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Test_Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <style>
            .mycss table tr td table tr td span { color:red; }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="mycss">
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="ObjectDataSource1" OnRowCreated="GridView1_RowCreated" PageSize="2">
            </asp:GridView>
        </div>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllResources" TypeName="SooGift.BLL.Auth.Resource">
                <SelectParameters>
                    <asp:Parameter DefaultValue="true" Name="onlyShowInNavigation" Type="Boolean" />
                </SelectParameters>
            </asp:ObjectDataSource>
        </form>
    </body>
    </html>
    所选页数字就是红色的,当然你可以随便设置样式
      

  9.   

    用javascript脚本就好了,干吗非整得那么麻烦,怕别人不知道你会服务器端语言吗????
      

  10.   

    kubbye(小蛤蟆就是我) :
    你寫出來看看呢,學習一下。