CSDN博客

img qi_gu

obout tree view 做 sub load功能的冬冬.很好玩哦.

发表于2004/12/30 18:34:00  905人阅读

<%@ Page Language="C#" ASPCOMPAT="TRUE" Debug="true" %>
<%@ Import Namespace="obout_ASPTreeView_2_NET" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="C#" runat="server">
void Page_Load(object sender, EventArgs e) {
 obout_ASPTreeView_2_NET.Tree oTree = new obout_ASPTreeView_2_NET.Tree();
 
 string ParentID,html,chkid,chkname,clickstr;//clickstr用来放onclik=obt2c语句的
 string subload;
 ParentID=Request.QueryString["ParentID"];
 oTree.FolderIcons = "/TreeIcons/Icons";
 oTree.FolderStyle = "/TreeIcons/Styles/Classic";
 if (ParentID==null)
 {
  oTree.AddRootNode("图层信息","search_globe.gif");
 }
 oTree.ShowIcons = false;

 SqlConnection myConn = new SqlConnection("server=localhost;uid=sa;pwd=guqi123456;database=odgweb");
 String CommStr="SELECT layerid, parentlayer, layername, expanded, icon,haschildren FROM maplayer ";
 String OrdStr=" ORDER BY parentlayer, layerid ";
  
 if (ParentID==null)
 {
  CommStr=CommStr+" where parentlayer is null";
 }else
 {
  CommStr=CommStr+" where parentlayer="+"'"+ParentID+"'";

 }
 
 SqlCommand myComm = new SqlCommand(CommStr+OrdStr, myConn);
 myConn.Open();
 SqlDataReader myReader = myComm.ExecuteReader();
   while (myReader.Read())
   {
  if (myReader.IsDBNull(1))
  {
    ParentID = "root";//根节点用root表示.
    clickstr="onclick=ob_t2c(this)";
    subload="/odg/layerview.aspx?ParentID="+myReader.GetString(0);
  }
  else
  {
    ParentID ="id"+myReader.GetString(1);
    if (myReader.GetBoolean(5))
    {
   clickstr="onclick=ob_t2c(this)";
   subload="/odg/layerview.aspx?ParentID="+myReader.GetString(0);
   
    }
    else
    {
   clickstr="";
   subload=null;
    }
  }
  chkid="chk_"+myReader.GetString(0);
  chkname="chk_"+myReader.GetString(0);
  html = String.Format("<input type='checkbox' class='chk' id={0}' name={1} {2}>{3}",chkid,chkname,clickstr,myReader.GetString(2));
  oTree.Add("root", "id" + myReader.GetString(0), html, myReader.GetBoolean(3), null,subload);
   }
 TreeView.Text = oTree.HTML();
 myReader.Close();
 myConn.Close();
}
</script>

<html>
<body>
  <ASP:Literal id="TreeView" runat="server" />
</body>
</html>

0 0

相关博文

我的热门文章

img
取 消
img