1个回答
展开全部
treeView1.DataSource = GetData();
treeView1.DataTextField = "Name";
treeView1.DataValueField = "ID";
treeView1.DataBind();
类似这样,用数据绑定,在Page_Load方法里面
treeView1.DataTextField = "Name";
treeView1.DataValueField = "ID";
treeView1.DataBind();
类似这样,用数据绑定,在Page_Load方法里面
更多追问追答
追问
那DB层 怎么把数据放到treeView控件中?
追答
public DataTable GetDate()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(Int32));
dt.Columns.Add("Name", typeof(string));
//..其他字段
DbConnection conn = .....
DbCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from ....";
DbDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
DataRow row = dt.CreateRow();
row["ID"] = reader["ID"];
row["Name"] = reader["Name"];
//....其他字段
dt.Rows.Add(row);
}
return dt;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询