treeview 动态绑定 无刷新 treeview控件 放在updatepanel中 点击节点还是刷新??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string sql = "select * from T_newstype where T_type=0"; DataSet ds = Code.DB.Serchtb(sql, "newstype"); for (int i = 0; i < ds.Tables["newstype"].Rows.Count; i++) { TreeNode tn = Code.Comm.Outtree(ds.Tables["newstype"].Rows[i]["T_id"].ToString(), ds.Tables["newstype"].Rows[i]["T_name"].ToString()); this.NewsTree.Nodes.Add(tn); DataSet dsxl = Code.DB.Serchtb("select * from T_newstype where T_type='" + tn.Value + "'", "newstypexl"); for (int j = 0; j < dsxl.Tables["newstypexl"].Rows.Count; j++) { TreeNode tnxl = Code.Comm.Outtree(dsxl.Tables["newstypexl"].Rows[j]["T_id"].ToString(), dsxl.Tables["newstypexl"].Rows[j]["T_name"].ToString()); tn.ChildNodes.Add(tnxl); } } 什么都不用:http://dazhzp.cn/logonx.aspx?id=0你试下吧再不明,看下msdn吧 <asp:TreeView ID="TVProduct" runat="server" OnSelectedNodeChanged="TVProduct_SelectedNodeChanged" Height="100%" ImageSet="Faq"> <ParentNodeStyle Font-Bold="False" ImageUrl="~/images/2.png" /> <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" /> <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px" ImageUrl="~/image/0.png" VerticalPadding="0px" /> <RootNodeStyle ImageUrl="~/images/1.png" /> <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" ImageUrl="~/images/3.png" NodeSpacing="0px" VerticalPadding="1px" /> </asp:TreeView> public partial class Control_left_Product : System.Web.UI.UserControl{ TreeNode root = new TreeNode(); TreeNode leaf = new TreeNode(); TreeNode subleaf = new TreeNode(); List<Model.ProductType> lists; List<Model.GrassType> list; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindTreeView(); } } public void BindTreeView() { if (TVProduct.Nodes.Count == 0) { root.Text = "产品类别"; root.Value = "0"; TVProduct.Nodes.Add(root); TVProduct.ExpandAll(); } lists = new BLL.ProductType().Select(""); foreach (Model.ProductType model in lists) //treeview加载大类别 { leaf = new TreeNode(); leaf.Text = model.Type_Name; leaf.Value =model.Type_Id.ToString(); root.ChildNodes.Add(leaf); BindSubLeaf(model.Type_Id); leaf.Collapse(); } } public void BindSubLeaf(int Pro_TypeId) //绑定子节点,展开后每一类最后一个节点(treeview加载小类别) { list = new BLL.GrassType().Selects(Pro_TypeId); foreach (Model.GrassType models in list) { subleaf = new TreeNode(); subleaf.Text = models.Type_Name; subleaf.Value = models.Type_Id.ToString(); leaf.ChildNodes.Add(subleaf); } } protected void TVProduct_SelectedNodeChanged(object sender, EventArgs e) { string NodesName = TVProduct.SelectedNode.Text; //选择当前节点 if (TVProduct.SelectedNode.ChildNodes.Count!=0) //判断子节点下面没有节点 { lists = new BLL.ProductType().Select(""); foreach (Model.ProductType Pro_Model in lists) { if (NodesName == Pro_Model.Type_Name) { int Pro_TypeId = Pro_Model.Type_Id; Session["Pro_TypeId"] = Pro_TypeId; Session["Gra_TypeId"] = 0; Response.Redirect("Products.aspx?siteMapName="+NodesName); } } } else { string NodesParent = TVProduct.SelectedNode.Parent.Text; //当前节点的父节点 lists = new BLL.ProductType().Select(""); foreach (Model.ProductType Pro_Models in lists) { if (NodesParent == Pro_Models.Type_Name) { int Pro_TypeId = Pro_Models.Type_Id; Session["Pro_TypeId"] = Pro_TypeId; } } list = new BLL.GrassType().Select(""); foreach (Model.GrassType Grass_Model in list) { if (NodesName == Grass_Model.Type_Name) { TVProduct.SelectedNode.Parent.ToggleExpandState(); int Gra_TypeId = Grass_Model.Type_Id; Session["Gra_TypeId"] = Gra_TypeId; Response.Redirect("Products.aspx?siteMapName=" + NodesName + "&NodesParent=" + NodesParent); } } }} } updatepanel1呢?如果你用的是ASP。NETR 2。0需要在ScriptManger中显示声明,允许局部刷新 。 放在 updatel1 中 有ScriptManger显示声明!!! 动态绑定的treeview节点,刷新无法避免,除非用js读取和绑定数据 无刷新就用JS来实现吧this.TreeView1.Attributes.Add("onclick ", "GetTitle();return false "); [code=HTML][ <script type="text/javascript"> function GetTitle() { var Obj = event.srcElement; alert(Obj.innerText); } </script>/code] 上个前台JS弄乱了 <script type="text/javascript"> function GetTitle() { var Obj = event.srcElement; alert(Obj.innerText); } </script> A Strange Question. 【在线】想在网站里加个别人做好的论坛,两个web.config,出错。谢谢! 如何保持treeview各个节点的状态? 怎么去掉htm格式? 发现一个奇妙的现象,用web也能关机? frame的问题 问一个数据库 绑定的 简单问题~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~马上给分 调试时,出现401错误,死活找不出原因来 这段代码缺少什么不能运行? 想问问ASP.net的一些情况!! asp.net dll 反编译后重新编译问题,高分请教 vs2008中间添加一个html类型的table控件。结果报错
DataSet ds = Code.DB.Serchtb(sql, "newstype");
for (int i = 0; i < ds.Tables["newstype"].Rows.Count; i++)
{
TreeNode tn = Code.Comm.Outtree(ds.Tables["newstype"].Rows[i]["T_id"].ToString(), ds.Tables["newstype"].Rows[i]["T_name"].ToString());
this.NewsTree.Nodes.Add(tn);
DataSet dsxl = Code.DB.Serchtb("select * from T_newstype where T_type='" + tn.Value + "'", "newstypexl");
for (int j = 0; j < dsxl.Tables["newstypexl"].Rows.Count; j++)
{
TreeNode tnxl = Code.Comm.Outtree(dsxl.Tables["newstypexl"].Rows[j]["T_id"].ToString(), dsxl.Tables["newstypexl"].Rows[j]["T_name"].ToString());
tn.ChildNodes.Add(tnxl);
}
}
http://dazhzp.cn/logonx.aspx?id=0你试下吧
再不明,看下msdn吧
Height="100%" ImageSet="Faq">
<ParentNodeStyle Font-Bold="False" ImageUrl="~/images/2.png" />
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
ImageUrl="~/image/0.png" VerticalPadding="0px" />
<RootNodeStyle ImageUrl="~/images/1.png" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
ImageUrl="~/images/3.png" NodeSpacing="0px" VerticalPadding="1px" />
</asp:TreeView>
{
TreeNode root = new TreeNode();
TreeNode leaf = new TreeNode();
TreeNode subleaf = new TreeNode();
List<Model.ProductType> lists;
List<Model.GrassType> list;
protected void Page_Load(object sender, EventArgs e)
{ if (!Page.IsPostBack)
{
BindTreeView();
}
}
public void BindTreeView()
{ if (TVProduct.Nodes.Count == 0)
{
root.Text = "产品类别";
root.Value = "0";
TVProduct.Nodes.Add(root);
TVProduct.ExpandAll();
}
lists = new BLL.ProductType().Select("");
foreach (Model.ProductType model in lists) //treeview加载大类别
{
leaf = new TreeNode();
leaf.Text = model.Type_Name;
leaf.Value =model.Type_Id.ToString();
root.ChildNodes.Add(leaf);
BindSubLeaf(model.Type_Id);
leaf.Collapse();
}
} public void BindSubLeaf(int Pro_TypeId) //绑定子节点,展开后每一类最后一个节点(treeview加载小类别)
{
list = new BLL.GrassType().Selects(Pro_TypeId);
foreach (Model.GrassType models in list)
{
subleaf = new TreeNode();
subleaf.Text = models.Type_Name;
subleaf.Value = models.Type_Id.ToString();
leaf.ChildNodes.Add(subleaf);
}
}
protected void TVProduct_SelectedNodeChanged(object sender, EventArgs e)
{
string NodesName = TVProduct.SelectedNode.Text; //选择当前节点
if (TVProduct.SelectedNode.ChildNodes.Count!=0) //判断子节点下面没有节点
{
lists = new BLL.ProductType().Select("");
foreach (Model.ProductType Pro_Model in lists)
{
if (NodesName == Pro_Model.Type_Name)
{
int Pro_TypeId = Pro_Model.Type_Id;
Session["Pro_TypeId"] = Pro_TypeId;
Session["Gra_TypeId"] = 0;
Response.Redirect("Products.aspx?siteMapName="+NodesName);
}
}
}
else
{
string NodesParent = TVProduct.SelectedNode.Parent.Text; //当前节点的父节点
lists = new BLL.ProductType().Select("");
foreach (Model.ProductType Pro_Models in lists)
{
if (NodesParent == Pro_Models.Type_Name)
{
int Pro_TypeId = Pro_Models.Type_Id;
Session["Pro_TypeId"] = Pro_TypeId;
}
}
list = new BLL.GrassType().Select("");
foreach (Model.GrassType Grass_Model in list)
{
if (NodesName == Grass_Model.Type_Name)
{
TVProduct.SelectedNode.Parent.ToggleExpandState();
int Gra_TypeId = Grass_Model.Type_Id;
Session["Gra_TypeId"] = Gra_TypeId;
Response.Redirect("Products.aspx?siteMapName=" + NodesName + "&NodesParent=" + NodesParent);
}
}
}
} }
如果你用的是ASP。NETR 2。0需要在ScriptManger中显示声明,允许局部刷新 。
[code=HTML][ <script type="text/javascript">
function GetTitle() {
var Obj = event.srcElement;
alert(Obj.innerText);
} </script>/code]
function GetTitle() {
var Obj = event.srcElement;
alert(Obj.innerText);
} </script>