public static void FillTreeView(TreeView tv)
{
SqlCommon sqlHelp = new SqlCommon();
DataSet ds = null;
int product_sort = GetSortIdByProductSortName("鲜花");
foreach (TreeNode node in tv.Nodes)
{
if (node.Text.Equals("用途"))
{
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@product_sort", product_sort);
ds = sqlHelp.CreateDataSet("select * from product_useNames where product_sort=@product_sort", param);
if (ds == null)
{
return;
}
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode childNode = new TreeNode(dr["name"].ToString());
string id = dr["id"].ToString();
childNode.NavigateUrl = "~/flower/search.aspx?strUse=" + id.ToString();
node.ChildNodes.Add(childNode);
}
}
else if (node.Text.Equals("材料"))
{
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@product_sort", product_sort);
ds = sqlHelp.CreateDataSet("select * from product_materialNames where product_sort=@product_sort", param);
if (ds == null)
{
return;
}
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode childNode = new TreeNode(dr["name"].ToString());
string id = dr["id"].ToString();
childNode.NavigateUrl = "~/flower/search.aspx?strObject=" + id.ToString();
node.ChildNodes.Add(childNode);
}
}
else if (node.Text.Equals("对象"))
{
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@product_sort", product_sort);
ds = sqlHelp.CreateDataSet("select * from product_objectNames where product_sort=@product_sort", param);
if (ds == null)
{
return;
}
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode childNode = new TreeNode(dr["name"].ToString());
string id = dr["id"].ToString();
childNode.NavigateUrl = "~/flower/search.aspx?strObject=" + id.ToString();
node.ChildNodes.Add(childNode);
}
}
}
}
FillTreeView(tvNavigator);
我的tvNavigator是treeview控件。为什么运行完会说:未将对象引用设置到对象的实例。帮忙看看,谢谢了。