private void button1_Click(object sender, EventArgs e)
{
//using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ToString()))
//{
// SqlDataAdapter sda = new SqlDataAdapter("Select * From T_Class Where F_Type='Product' order by F_RootID,F_Orders", conn);
// DataSet Ds = new DataSet();
// sda.Fill(Ds, "T_Class");
// //使用DataSet绑定时,必须同时指明DateMember
// //this.dataGridView1.DataSource = Ds;
// //this.dataGridView1.DataMember = "T_Class";
// //也可以直接用DataTable来绑定
// this.dataGridView1.DataSource = Ds.Tables["T_Class"];
//}
//甚至直接直接绑定数组
ArrayList AL = new ArrayList();
AL.Add(new myItem("text1", "value1"));
AL.Add(new myItem("text2", "value2"));
AL.Add(new myItem("text3", "value3"));
this.dataGridView1.DataSource = AL;
}
class myItem
{
private string _Text;
private string _Value;
public myItem(string text, string value)
{
this._Text = text;
this._Value = value;
}
public string Text {
set { _Text = value; }
get { return _Text; }
}
public string Value
{
set { _Value = value; }
get { return _Value; }
}
}
{
//using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ToString()))
//{
// SqlDataAdapter sda = new SqlDataAdapter("Select * From T_Class Where F_Type='Product' order by F_RootID,F_Orders", conn);
// DataSet Ds = new DataSet();
// sda.Fill(Ds, "T_Class");
// //使用DataSet绑定时,必须同时指明DateMember
// //this.dataGridView1.DataSource = Ds;
// //this.dataGridView1.DataMember = "T_Class";
// //也可以直接用DataTable来绑定
// this.dataGridView1.DataSource = Ds.Tables["T_Class"];
//}
//甚至直接直接绑定数组
ArrayList AL = new ArrayList();
AL.Add(new myItem("text1", "value1"));
AL.Add(new myItem("text2", "value2"));
AL.Add(new myItem("text3", "value3"));
this.dataGridView1.DataSource = AL;
}
class myItem
{
private string _Text;
private string _Value;
public myItem(string text, string value)
{
this._Text = text;
this._Value = value;
}
public string Text {
set { _Text = value; }
get { return _Text; }
}
public string Value
{
set { _Value = value; }
get { return _Value; }
}
}