none
dataGrid RRS feed

答案

  • 这个要手动添加, datagrid没有默认的支持自动编号的列: 1    private int rowscount = 0;

    Code Snippet
     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.EmployeeID
    18                                 FROM Employees INNER JOIN
    19                       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}

     

     


     

    2008年11月24日 5:50
    版主