DataGrid Item auto-generate serial number
when AllowPaging=False
or
AllowPaging="True"
Reverse order:
//have been defined:
private int RowsCount = ds.Tables[0].Rows.Count
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# Container.ItemIndex + 1%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# Container.ItemIndex + 1%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
or
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# this.DataGrid1.Items.Count + 1%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# this.DataGrid1.Items.Count + 1%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
AllowPaging="True"
<asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# this.DataGrid1.CurrentPageIndex * this.DataGrid1.PageSize + Container.ItemIndex + 1%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# this.DataGrid1.CurrentPageIndex * this.DataGrid1.PageSize + Container.ItemIndex + 1%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Reverse order:
//have been defined:
private int RowsCount = ds.Tables[0].Rows.Count
asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# RowsCount - DataGrid1.CurrentPageIndex * DataGrid1.PageSize - Container.ItemIndex %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# RowsCount - DataGrid1.CurrentPageIndex * DataGrid1.PageSize - Container.ItemIndex %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>