关于WebUI中WebGrid的层次结构,代码绑定数据


            
                
                    
                        
                            
                                
                                    
                                    
                                
                            
                        
                        
                            
                            
                            
                            
                        
                    
                
                
                    
                    
                    
                    
                
            
            
                
                
                
                
                    
                    
                    
                    
                    
                        
                    
                
                
                
                
                    
                    
                
                
                
                
                
                
                
                
                
                    
                
                
                
                
                
                
            
        


 

 


public DataSet GetDataSet()
    {
        string oleStr = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + Server.MapPath("~/App_Data/NorthWind.mdb");
        DataSet ds = new DataSet();
        string sqlStr1 = "select * from Customers where CustomerID='ALFKI'";
        string sqlStr2 = "select * from Orders where CustomerID ='ALFKI'"; //
        string sqlStr3 = "select * from [Order Details] where OrderID in (select OrderID from Orders where CustomerID ='ALFKI')";// 

        OleDbConnection oleConn = new OleDbConnection(oleStr);
        oleConn.Open();
        OleDbDataAdapter oleAdpt1 = new OleDbDataAdapter(sqlStr1, oleConn);
        OleDbDataAdapter oleAdpt2 = new OleDbDataAdapter(sqlStr2, oleConn);
        OleDbDataAdapter oleAdpt3 = new OleDbDataAdapter(sqlStr3, oleConn);
        oleAdpt1.Fill(ds, "Customers");
        oleAdpt2.Fill(ds, "Orders");
        oleAdpt3.Fill(ds, "Order Details");
        DataColumn DcParent = new DataColumn();
        DataColumn DcChild = new DataColumn();
        DcParent = ds.Tables["Customers"].Columns["CustomerID"];
        DcChild = ds.Tables["Orders"].Columns["CustomerID"];
        DataRelation DrCustomers = new DataRelation("RelationCustomers", DcParent, DcChild);
        ds.Relations.Add(DrCustomers);

        DcParent = ds.Tables["Orders"].Columns["OrderID"];
        DcChild = ds.Tables["Order Details"].Columns["OrderID"];
        DataRelation DrOrders = new DataRelation("RelationOrders", DcParent, DcChild);
        ds.Relations.Add(DrOrders);
        oleConn.Close();
        return ds;
    }

    protected void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
    {
        DataSet ds = GetDataSet();
        e.DataSource = ds;

    }


 

 

你可能感兴趣的:(WEBUI,dataset,string,object,server,c)