1 < asp:DataGrid id =DataGrid1 runat =server > 2 < Columns > 3 < asp:TemplateColumn > 4 < ItemTemplate > 5 <% # Container.ItemIndex + 1 %> 6 </ ItemTemplate > 7 </ asp:TemplateColumn > 8 </ Columns > 9 </ asp:DataGrid > 1 < asp:DataGrid id =DataGrid1 runat =server > 2 < Columns > 3 < asp:TemplateColumn > 4 < ItemTemplate > 5 <% # this.DataGrid1.Items.Count + 1 %> 6 </ ItemTemplate > 7 </ asp:TemplateColumn > 8 </ Columns > 9 </ asp:DataGrid > 1 < asp:DataGrid id =DataGrid1 runat =server AllowPaging =True > 2 < Columns > 3 < asp:TemplateColumn > 4 < ItemTemplate > 5 <% # this.DataGrid1.CurrentPageIndex * this.DataGrid1.PageSize + Container.ItemIndex + 1 %> 6 </ ItemTemplate > 7 </ asp:TemplateColumn > 8 </ Columns > 9 </ asp:DataGrid >
1 private int rowscount = 0 ; 2 protected int RowsCount 3 { 4 get{ return rowscount;} 5 set{ this.rowscount = value; } 6 } 7 8 private void Page_Load( object sender, System.EventArgs e) 9 { 10 // 在此处放置用户代码以初始化页面11 if(!IsPostBack)12 this.BindData();13 } 14 private void BindData() 15 { 16 SqlConnection cn = new SqlConnection(server=(local);database=NorthWind;uid=sa;pwd=);17 string str=@SELECT Employees.EmployeeID, Orders.EmployeeID18 FROM Employees INNER JOIN19 Orders ON Employees.EmployeeID = Orders.EmployeeID ;20 SqlDataAdapter sqlda = new SqlDataAdapter(str,cn);21 DataSet ds = new DataSet();22 sqlda.Fill(ds);23 this.RowsCount = ds.Tables[0].Rows.Count;24 this.DataGrid1.DataSource = ds;25 this.DataGrid1.DataBind();26} 1 < asp:DataGrid id =DataGrid1 runat =server AllowPaging =True > 2 < Columns > 3 < asp:TemplateColumn > 4 < ItemTemplate > 5 <% # RowsCount - DataGrid1.CurrentPageIndex * DataGrid1.PageSize - Container.ItemIndex %> 6 </ ItemTemplate > 7 </ asp:TemplateColumn > 8 </ Columns > 9 </ asp:DataGrid > |