第一種方式,直接在Aspx頁面GridView模板列中.這種的缺點(diǎn)是到第二頁分頁時(shí)又重新開始了.
復(fù)制代碼 代碼如下:
asp:TemplateField HeaderText="序號" InsertVisible="False">
ItemTemplate>
%#Container.DataItemIndex+1%>
/ItemTemplate>
/asp:TemplateField>
第二種方式分頁時(shí)進(jìn)行了計(jì)算,這樣會(huì)累計(jì)向下加.
復(fù)制代碼 代碼如下:
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代碼中,和第二種相似.
復(fù)制代碼 代碼如下:
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事件用法實(shí)例
- C#中GridView動(dòng)態(tài)添加列的實(shí)現(xiàn)方法
- C#實(shí)現(xiàn)DataGridView控件行列互換的方法
- C#實(shí)現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法
- C#中DataGridView常用操作實(shí)例小結(jié)
- C#實(shí)現(xiàn)3步手動(dòng)建DataGridView的方法
- asp.net中GridView數(shù)據(jù)鼠標(biāo)移入顯示提示信息
- C#中DataGridView動(dòng)態(tài)添加行及添加列的方法
- GridView使用學(xué)習(xí)總結(jié)
- 如何用jQuery實(shí)現(xiàn)ASP.NET GridView折疊伸展效果
- ASP.NET GridView中加入RadioButton不能單選的解決方案
- DataGridView展開與收縮功能實(shí)現(xiàn)
- GridView控件如何顯示序號