GridView控件自动编号实现
2012-06-29 15:33
323 查看
GridView控件自动编号实现,主要有二种方法
一、
<asp:TemplateField HeaderText="序号" ItemStyle-Width="50px" HeaderStyle-Width="50px">
<ItemStyle HorizontalAlign="Center" Wrap="false" />
<ItemTemplate>
<%#Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
二、
protected void gvDataTypeManage_RowDataBound(object sender, GridViewRowEventArgs e)
{
//自动编号实现
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
注意:当有分页控件一起使用时,一分页后,编号又是从0开始了,这时候,我们可以加上 当前页索引*页面大小。其中ExtendPager1是分页控件
protected void gvMethodInfoManage_RowDataBound(object sender, GridViewRowEventArgs e)
{
//自动编号实现
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + ExtendPager1.PageSize * (ExtendPager1.PageIndex - 1) + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
一、
<asp:TemplateField HeaderText="序号" ItemStyle-Width="50px" HeaderStyle-Width="50px">
<ItemStyle HorizontalAlign="Center" Wrap="false" />
<ItemTemplate>
<%#Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
二、
protected void gvDataTypeManage_RowDataBound(object sender, GridViewRowEventArgs e)
{
//自动编号实现
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
注意:当有分页控件一起使用时,一分页后,编号又是从0开始了,这时候,我们可以加上 当前页索引*页面大小。其中ExtendPager1是分页控件
protected void gvMethodInfoManage_RowDataBound(object sender, GridViewRowEventArgs e)
{
//自动编号实现
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + ExtendPager1.PageSize * (ExtendPager1.PageIndex - 1) + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
相关文章推荐
- GridView控件实现支持分页的自动编号代码
- GridView实现自动编号
- .NET中GridView实现自动编号
- 如何实现:GridView 控件中显示的文本不自动换行,隐藏超出宽度部分wj-wangjun
- ASPxGridView中实现自动编号
- GridView实现自动编号
- GridView实现自动编号
- GridView实现自动编号
- GridView实现自动编号;GridView实现自定义时间货币等字符串格式;GridView实现用“...”代替超长字符串;GridView一般换行与强制换行;GridView显示隐藏某一列;
- GridView实现自动编号
- GridView实现 自动编号(转)
- GridView实现自动编号
- GridView实现自动编号及鼠标移到GridView某一行时改变该行的背景色
- access如何用代码在“默认值”里实现自动编号?单据流
- Gridview 设置自动编号列
- C#实现Dll(OCX)控件自动注册的两种方法
- 实现GridView控件的删除多条记录功能系列(3)
- 用Gridview和AspNetPager控件实现真分页(二)
- Dev的Gridview控件,实现 每一行行的双击的事件
- 在Oracle Form中,如何实现自动编号(行号)的功能