一个数据表实现二级关联显示的办法

 1 //获得二级菜单
 2 public static string SecondMenu(string strParent)
 3 
 4 strSecondMenu = null;
 5 string Sqlstr = "select module_code,module_parent,module_show from [dic_modules] where (module_parent = '" + strParent + "' and module_status = '1')  order by module_code";
 6 SqlDataAdapter daDetail = new SqlDataAdapter(Sqlstr,doData.conn);
 7 DataSet dsDetail = new DataSet();
 8 daDetail.Fill(dsDetail);
 9 int ccount = dsDetail.Tables[0].Rows.Count ;
10 for(int dr = 0; dr < ccount;dr++)
11 {
12 strSecondMenu += " <input type=\"checkbox\" name=\"selItem\" value=\""+dsDetail.Tables[0].Rows[dr][0].ToString()+"\" onclick=\"select_firstItem('" + strParent + "');\"><font color=\"#666666\""+dsDetail.Tables[0].Rows[dr][2].ToString()+"</font>"+hk(dr)+"";
13 }
14 strSecondMenu = strSecondMenu+kh;
15 return strSecondMenu; 
16 }
17 
18 //返回二级菜单包含的value字符串
19 public static string SecondMenuValue(string strParent)
20 
21 strSecondMenuValue = null;
22 string Sqlstr = "select module_code from [dic_modules] where (module_parent = '" + strParent + "' and module_status = '1')  order by module_code";
23 SqlDataAdapter daDetailValue = new SqlDataAdapter(Sqlstr,doData.conn);
24 DataSet dsDetailValue = new DataSet();
25 daDetailValue.Fill(dsDetailValue);
26 int ccount = dsDetailValue.Tables[0].Rows.Count ;
27 for(int dr = 0; dr < ccount;dr++)
28 {
29 if(ccount>0)
30 strSecondMenuValue += ""+dsDetailValue.Tables[0].Rows[dr][0].ToString()+"|";
31 }
32 if(strSecondMenuValue != null)
33 strSecondMenuValue=strSecondMenuValue.Substring(0,strSecondMenuValue.Length-1);
34 return strSecondMenuValue; 
35 }
36 
37 //添加换行符
38 public static string hk(int strkh)
39 
40 kh = null;
41 if((strkh+1)%4==0)
42 {
43 kh = "<br>";
44 }
45 return kh; 
46 }
47 
48 
49 
50 
51 //一级权限菜单
52 public void roleMenu()
53 {
54 strFirstMenu =null;
55 doData.conn.Open();
56 string    strSql = "select module_code,module_show  from [dic_modules] where (module_parent = '1' and module_status = '1') order by module_code";
57 SqlDataAdapter da = new SqlDataAdapter(strSql,doData.conn);
58 DataSet ds = new DataSet();
59 da.Fill(ds,"dic_modules");
60 count = ds.Tables[0].Rows.Count;
61 
62 string begin = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"500\"  height=\"100%\">";
63 for(int rb = 0; rb < count;rb++)
64 {
65 strFirstMenu += "<tr onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='FDF0BC'\" onmouseout=\"this.style.backgroundColor=currentcolor\"><td width=\"80\" height=\"30\" valign=\"top\"> <input type=\"checkbox\" name=\"selItem\" value=\""+ds.Tables[0].Rows[rb][0].ToString()+"\" onclick=\"set_Item('"+SecondMenuValue(ds.Tables[0].Rows[rb][0].ToString())+"',this);\"><font color=\"#666666\">  "+ds.Tables[0].Rows[rb][1].ToString()+" </font></td><td width=\"420\" height=\"30\"  valign=\"top\""+SecondMenu(ds.Tables[0].Rows[rb][0].ToString())+"  </td></tr>";
66 }
67 
68 string FirstMenu = begin+strFirstMenu+"</table>";
69 doData.conn.Close();
70 Response.Write(FirstMenu);
71 }

posted on 2006-03-31 16:33  aliketen  阅读(1279)  评论(0)    收藏  举报

导航