GridView自動增加序號(三種實現(xiàn)方式)
更新時間:2013年04月17日 15:53:03 作者:
第一種方式,直接在Aspx頁面GridView模板列中.這種的缺點是到第二頁分頁時又重新開始了,第二種方式分頁時進行了計算,這樣會累計向下加,點三種放在cs代碼中
第一種方式,直接在Aspx頁面GridView模板列中.這種的缺點是到第二頁分頁時又重新開始了.
<asp:TemplateField HeaderText="序號" InsertVisible="False">
<ItemTemplate>
<%#Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
第二種方式分頁時進行了計算,這樣會累計向下加.
<asp:TemplateField HeaderText="序號" InsertVisible="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center"/>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>' />
</ItemTemplate>
</asp:TemplateField>
還有一種方式放在cs代碼中,和第二種相似.
<asp:BoundField HeaderText="序號" ></asp:BoundField>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
int indexID = this.GridView1.PageIndex * this.myGridView.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = indexID.ToString();
}
}
復制代碼 代碼如下:
<asp:TemplateField HeaderText="序號" InsertVisible="False">
<ItemTemplate>
<%#Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
第二種方式分頁時進行了計算,這樣會累計向下加.
復制代碼 代碼如下:
<asp:TemplateField HeaderText="序號" InsertVisible="False">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center"/>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>' />
</ItemTemplate>
</asp:TemplateField>
還有一種方式放在cs代碼中,和第二種相似.
復制代碼 代碼如下:
<asp:BoundField HeaderText="序號" ></asp:BoundField>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
int indexID = this.GridView1.PageIndex * this.myGridView.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = indexID.ToString();
}
}
您可能感興趣的文章:
- C#處理datagridview虛擬模式的方法
- C#中datagridview的EditingControlShowing事件用法實例
- C#中GridView動態(tài)添加列的實現(xiàn)方法
- C#實現(xiàn)DataGridView控件行列互換的方法
- C#實現(xiàn)綁定DataGridView與TextBox之間關聯(lián)的方法
- C#中DataGridView常用操作實例小結(jié)
- C#實現(xiàn)3步手動建DataGridView的方法
- asp.net中GridView數(shù)據(jù)鼠標移入顯示提示信息
- C#中DataGridView動態(tài)添加行及添加列的方法
- GridView使用學習總結(jié)
- 如何用jQuery實現(xiàn)ASP.NET GridView折疊伸展效果
- ASP.NET GridView中加入RadioButton不能單選的解決方案
- DataGridView展開與收縮功能實現(xiàn)
- GridView控件如何顯示序號
相關文章
ASP.NET中實現(xiàn)jQuery Validation-Engine的Ajax驗證
在jQuery的表變驗證插件中Validation-Engine是一款高質(zhì)量的產(chǎn)品,提示效果非常精美,而且里面包含了AJAX驗證功能2012-06-06asp.net頁面與頁面之間傳參數(shù)值方法(post傳值和get傳值)
這篇文章主要介紹了asp.net頁面與頁面之間傳參數(shù)值方法,說明了post傳值和get傳值的使用方法,需要的朋友可以參考下2014-02-02ASP.NET中使用AspnetAccessProvider
ASP.NET中使用AspnetAccessProvider...2007-09-09IdentityServer4 QuckStart 授權與自定義Claims的問題
這篇文章主要介紹了IdentityServer4 QuckStart 授權與自定義Claims的問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04Asp.Mvc?2.0實現(xiàn)用戶注冊實例講解(1)
這篇文章主要介紹了Asp.Mvc?2.0如何實現(xiàn)用戶注冊,實例講解很細致,注冊功能是每個網(wǎng)站必不可少的組成部分,感興趣的的朋友可以參考下2015-08-08ASP.NET堆和棧二之值類型和引用類型的參數(shù)傳遞和內(nèi)存分配
這篇文章介紹了ASP.NET堆和棧中值類型和引用類型的參數(shù)傳遞和內(nèi)存分配,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08ASP.NET導出Excel打開時提示:與文件擴展名指定文件不一致解決方法
ASP.NET導出Excel,打開時提示“您嘗試打開文件'XXX.xls'的格式與文件擴展名指定文件不一致” 很是郁悶,于是搜集了一些解決方法,感興趣的朋友可以了解下2013-01-01