1.1 动态将一个新建表绑定到UltraWebGrid
data=new DataSet("SampleData");
data.Tables.Add("Materials");
data.Tables[0].Columns.Add("Product Name");
data.Tables[0].Columns.Add("Weight (lbs)");
data.Tables[0].Columns.Add("Price ($)");
data.Tables[0].Columns.Add("Truck #");
data.Tables[0].Rows.Add(new object[] {"Sand",500,50.00,"Truck 505"});
data.Tables[0].Rows.Add(new object[] {"Cement",250,50.00,"Truck 505"});
data.Tables[0].Rows.Add(new object[] {"Brick",1000,500.00,"Truck 590"});
data.Tables[0].Rows.Add(new object[] {"6\" Block",800,200.00,"Truck 590"});
data.Tables[0].Rows.Add(new object[] {"Clean Fill",750,20.00,"Truck 533"});
data.Tables[0].Rows.Add(new object[] {"Top Soil",2000,200.00,"Truck 501"});
UltraWebGrid1.DataSource=data.Tables[0].DefaultView;
UltraWebGrid1.DataBind();
1.2 动态将一个新建表绑定到UltraWebGrid
System.Data.DataTable table = new System.Data.DataTable();
System.Data.DataColumn Col1 = new System.Data.DataColumn("PhoneNumbers", Type.GetType("System.Double"));
System.Data.DataColumn Col2 = new System.Data.DataColumn("Numbers", Type.GetType("System.Double"));
System.Data.DataColumn Col3 = new System.Data.DataColumn("Dates", Type.GetType("System.DateTime"));
System.Data.DataColumn Col4 = new System.Data.DataColumn("Currency", Type.GetType("System.Double"));
dateFormatUS.ShortDatePattern = "MM/dd/yyyy";
table.Columns.Add(Col1);
table.Columns.Add(Col2);
table.Columns.Add(Col3);
table.Columns.Add(Col4);
DataRow aRow = table.NewRow();
aRow[0] = 6094482000;
aRow[1] = 111111111;
aRow[2] = DateTime.Parse("2 / 22 / 02", dateFormatUS);
aRow[3] = 12;
table.Rows.Add(aRow);
aRow = table.NewRow();
aRow[0] = 6094482017;
aRow[1] = 123456789;
aRow[2] = DateTime.Parse("3 / 8 / 02", dateFormatUS);
aRow[3] = 5678.22;
table.Rows.Add(aRow);
aRow = table.NewRow();
aRow[0] = 8002318588;
aRow[1] = 987654321;
aRow[2] = DateTime.Parse("10 / 19 / 71", dateFormatUS);
aRow[3] = 100000.99;
table.Rows.Add(aRow);
//bind to grid
UltraWebGrid1.DataSource = table;
UltraWebGrid1.DataBind();
2 通过一般的方法将一个数据库中的表绑定到UltraWebGrid
string connectionString = "Server=.; Database=Northwind; Integrated Security=True;";
string sqlConnection = "select * from Customers";
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter cmdCustomer = new SqlDataAdapter(sqlConnection,connection);
DataSet ds = new DataSet();
cmdCustomer.Fill(ds,"Customers");
UltraWebGrid1.DataSource = ds;
UltraWebGrid1.DataBind();
3 通过DAAB将一个数据库中的表绑定到UltraWebGrid
string connectionString = "Server=.; Database=StarFGS; Integrated Security = True;";
string sqlConnection = "select * from spflml";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
DataSet ds = SqlHelper.ExecuteDataset(connection,CommandType.Text,sqlConnection);
UltraWebGrid2.DataSource=ds;
UltraWebGrid2.DataBind();
connection.Close();