zoukankan      html  css  js  c++  java
  • gridview 和repeater 添加序号的方法

    gridview添加序列号的方法:

    1、

    <asp:Label ID="lblSNum" runat="server"
    Text='<%# Container.DataItemIndex+1 %>'>
    </asp:Label>

    2、

    rowIndex = (this.GridView1.PageIndex) * GridView1.PageSize + 1;

    不太详细,加个示例,放到绑定函数里绑定之前

        private void LoadGrid()
        {
            try
            {
                DataTable dt = new Business.ComMngBiz.ComMngClin().QueryTCCLiFeeDetail(Convert.ToDecimal(is_Fclinid), is_FRCODE).Tables["TCCLIFEEDETAIL"];
                recordcount = dt.Rows.Count;
                rowIndex = (this.GridView1.PageIndex) * GridView1.PageSize + 1;
                this.GridView1.DataSource = dt;
                this.GridView1.DataBind();
               
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SetP3", "alert('" + ex.Message.Replace("\r", "").Replace("\n", "").Replace("'", "").Replace("\"", "") + "');", true);
            }
        }
     

    repeater加序列号的方法:

    1、<itemtemplate>
    <tr><td>
    <%# Container.ItemIndex + 1%>
    </td></tr>
    </itemtemplate>

    2、<itemtemplate>
    <tr><td>
    <%# this.rpResult.Items.Count + 1%>
    </td></tr>
    </itemtemplate>

    两种其它方法:
    在<form></form>中添加<Label ID="dd" ></Label>
    <body nload="show()">
    <Script. Language="JScript">
          function show()
       {
    var bj = document.all.tags("LABEL");
    for (i=0;i<obj.length;i++)
    {
    document.all["dd"][i].innerHTML=i+1;
    }
       }
       </script>
     
     
    4、后台实现方法

    后台实现方法:
    在.aspx里添加<asp:Label id="Label1" Runat="server"></asp:Label>
    在.cs里添加
    ** void InitializeComponent()
    {   
       this.Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater1_ItemDataBound);
       this.Load += new System.EventHandler(this.Page_Load);
    }
    ** void Repeater1_ItemDataBound(object source, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
       {
        ((Label)e.Item.FindControl("Label1")).Text = Convert.ToString(e.Item.ItemIndex + 1);
       }
    }

    5:连续的编号
    <%# Container.ItemIndex + 1 + (this.AspNetPager1.CurrentPageIndex -1) * 20%>

  • 相关阅读:
    【五校联考5day1】登山
    非旋Treap及其可持久化
    自然数幂求和——第二类Strling数
    [JZOJ6011] 【NOIP2019模拟1.25A组】天天爱跑步
    [JZOJ5232] 【NOIP2017模拟A组模拟8.5】带权排序
    FreeRTOS 任务通知模拟消息邮箱
    Python爬虫技术:爬虫时如何知道是否代理ip伪装成功?
    Python网络爬虫入门实战(爬取最近7天的天气以及最高/最低气温)
    Python numpy的基本操作你一般人都不会
    如何正确的使用Python解释器?你之前肯定用错了
  • 原文地址:https://www.cnblogs.com/ycxyyzw/p/2101329.html
Copyright © 2011-2022 走看看