北溟鱼逍遥游

王猛扪虱谈天下 孟德煮酒论英雄

导航

DataGrid Item auto-generate serial number

when AllowPaging=False
<asp:DataGrid id="DataGrid1" runat="server">
    
<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>

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>

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>

posted on 2005-01-06 09:37  北溟鱼逍遥游  阅读(1306)  评论(0编辑  收藏  举报