出自ProgWiki
在ASP.NET的GridView的版面設計中加入自動編號欄位
- 假如GridView的 id 是 GridView1
<asp:TemplateField HeaderText="序號">
<ItemTemplate>
<%#GridView1.PageIndex * GridView1.PageSize + GridView1.Rows.Count + 1%>
</ItemTemplate>
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:TemplateField>
在GridView的RowCreate事件中加入自動編號欄位
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.Header:
break;
case DataControlRowType.Footer:
break;
case DataControlRowType.DataRow:
TableCellCollection tcDataRow = e.Row.Cells;
tcDataRow[0].Text = (e.Row.RowIndex + 1).ToString(); //處理No欄位用(自動編號欄位)
break;
case DataControlRowType.EmptyDataRow:
break;
}
}
其他相關