不行了,TreeView控件动态加载数据库的问题!只差一点点了,实在没分了
我的数据量特别大,一次全加载太慢,我现在想让TreeView第一次加载只取第一级的数据,然后用户点啊个节点就会加载哪一级的数据,刷新就刷新吧,太着急了
我会用遍历一次把全部的数据加载出来,但是可刷新的一级一级的加就不会了,现在页面加载第一级后,单击节点,我在myTree_SelectedIndexChange事件中加载第二级和第三级,页面刷新后,所有的代码都没有问题,被单击的那个节点的子节点数据全部读出来,但是就是不会出现在页面上,大家救我!
private void Page_Load(object sender, System.EventArgs e)
{
TreeNode tmpNd= new TreeNode();
tmpNd.ID = "0 ";
tmpNd.Text = "中华人民共和国 ";
wd= "+tmpNd.Text+ " ";
myTree.Nodes.Add(tmpNd);
string strsql= "SELECT DISTINCT 行政区代码,名称 FROM 行政编码 WHERE 名称1 IS NULL ";
DataTable dt=Class.DataAccess.GetSqlData (strsql);
foreach (DataRow dr in dt.Rows )
{
tmpNd1= new TreeNode();
string name=dr[ "名称 "].ToString ();
string id=dr[ "行政区代码 "].ToString ();
tmpNd1.ID = " "+id+ " ";
tmpNd1.Text = " "+name+ " ";
tmpNd.Nodes.Add(tmpNd1);
}
}
private void myTree_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
{
//第二级
sValue=tmpNd1.ID .Substring(0,2);
string gcd= "SELECT 行政区代码,名称1 FROM 行政编码 WHERE (名称1 IS NOT NULL) AND (名称2 IS NULL) AND (行政区代码 like ' "+sValue + "% ') ";
DataTable mytab = Class.DataAccess.GetSqlData (gcd);
foreach (DataRow dr2 in mytab.Rows )
{
TreeNode tmpNd2= new TreeNode();
string name2=dr2[ "名称1 "].ToString ();
string id2=dr2[ "行政区代码 "].ToString ();
tmpNd2.ID = " "+id2+ " ";
tmpNd2.Text = " "+name2+ " ";
tmpNd2.NavigateUrl = "WebForm1.aspx?wd= "+tmpNd2.Text+ " ";
tmpNd1.Nodes.Add(tmpNd2);
//第三级
string sValue3=tmpNd2.ID .Substring(0,4);
string sql = "SELECT 行政区代码,名称2 FROM 行政编码 WHERE (名称2 IS NOT NULL) AND (行政区代码 like ' " + sValue3+ "% ') ";
DataTable mytab3 = Class.DataAccess.GetSqlData (sql);
foreach (DataRow dr3 in mytab3.Rows )
{
TreeNode tmpNd3= new TreeNode();
string name3=dr3[ "名称2 "].ToString ();
string id3=dr3[ "行政区代码 "].ToString ();
tmpNd3.ID = " "+id3+ " ";
tmpNd3.Text = " "+name3+ " ";
tmpNd3.NavigateUrl = "WebForm1.aspx?wd= "+tmpNd3.Text+ " ";
tmpNd2.Nodes.Add(tmpNd3);
//第四级
string sql4 = "select coid,机构名称1 from 政府通讯录 where 地区编码= ' "+tmpNd3.ID+ " ' and (编码= '10541 'or 编码= '10542 ' or 编码= '10543 ') ";
DataTable mytab4 = Class.DataAccess.GetSqlData (sql4);
foreach (DataRow dr4 in mytab4.Rows )
{
TreeNode tmpNd4= new TreeNode();