ASP.NET2.0 TreeView动态加载问题
aspx页面内容如下:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html Xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body bgcolor="white">
<form id="form1" runat="server">
<div>
<asp:treeview ID="Treeview1" runat="server" ImageSet="XPFileExplorer" AutoGenerateDataBindings="false" ExpandDepth="0"
OnTreeNodePopulate="Treeview1_TreeNodePopulate" ShowLines="True"
>
<SelectedNodeStyle BackColor="#B5B5B5"></SelectedNodeStyle>
<Nodes>
<asp:TreeNode Value="0" Text="C:" PopulateOnDemand="True">
</asp:TreeNode>
</Nodes>
<NodeStyle VerticalPadding="2px" Font-Names="Tahoma" Font-Size="8pt" HorizontalPadding="2px"
ForeColor="Black"></NodeStyle>
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA"></HoverNodeStyle>
</asp:treeview>
</div>
</form>
</body>
</html>
cs 文件:
using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Treeview1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
if (IsCallback)
if (e.Node.ChildNodes.Count == 0)
{
Response.Write(e.Node.Value);
LoadChildNode(e.Node);
//Response.Write("<script language='javascript'>alert('" + e.Node.Value.ToString() + "');</script>");
}
}
private void LoadChildNode(TreeNode node)
{
#region test
string connectionString = ConfigurationManager.ConnectionStrings["ece_libConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from leo_proclass where ClassID<>50 and parentid=" +node.Value.Trim(), con);
DataSet ds = new DataSet();
sda.Fill(ds, "dir");
foreach (DataRow dr in ds.Tables["dir"].Rows)//目录节点
{
TreeNode newNode = new TreeNode();
item info = new item(dr["ClassID"].ToString());//根据节点的value值创建目录
if (info.flag())
{
newNode.PopulateOnDemand = true;//节点允许被展开
newNode.SelectAction = TreeNodeSelectAction.SelectExpand;
}
else
{
newNode.PopulateOnDemand = false;//节点不允许被展开
}
newNode.Text = dr["ClassName"].ToString() + dr["ClassID"].ToString(); ;
newNode.Value = dr["ClassID"].ToString().Trim();//节点的完整路径名
node.ChildNodes.Add(newNode);//添加目录节点
}
con.Close();
#endregion
}
运行之后出现"Input string was not in a correct format"
实在解决不了!! --------------------编程问答--------------------
学习!!
我正要这样的DEMO,可以发份吗``
guohua2208@163.com --------------------编程问答-------------------- up --------------------编程问答-------------------- 遇到了同样的问题,我用treeview绑定.sitemap文件,在点击节点的时候就出现了这样的问题,本机测试没问题,放在服务器上就出现了这样的问题..
关注一下 --------------------编程问答-------------------- 我的问题解决!
我在web.config 中加了一句
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>
与.sitemap中的保持一致就OK了!
补充:.NET技术 , ASP.NET