Mennan Mennan - 3 months ago 22
ASP.NET (C#) Question

How to set treeview's childnode postback false on ASP.NET?

I have a treeview and i want no postback on click any childnodes.And i will get selected childnode value.
I found a solution , when i set "node_.SelectAction = TreeNodeSelectAction.None;" i cant select any childnodes and no highlight on it.

Waiting your helps.Sorry about my en.

Aspx:

<asp:TreeView ID="TreeView1" runat="server"></asp:TreeView>


Cs:

TreeView1.Nodes.Clear();
TreeView1.TreeNodeExpanded += new TreeNodeEventHandler(TreeView1_TreeNodeExpanded);

DataTable dt = ImzaDll.Imza.KategorileriGetir(true);

foreach (DataRow row in dt.Rows)
{
TreeNode node_ = new TreeNode();
node_.Text = row["ACIKLAMA"].ToString();
node_.Value = row["KATEGORI"].ToString();
TreeView1.Nodes.Add(node_);
}



void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
addChildNodes(e.Node);
}



private void addChildNodes(TreeNode node)
{
DataTable dt = ImzaDll.Imza.KutuphaneBasliklariGetir(true, node.Value.ToString());

foreach (DataRow row in dt.Rows)
{
TreeNode childNode = new TreeNode();
childNode.Text = row["BASLIK"].ToString();
childNode.Value = row["KUTUPHANE_ID"].ToString();
childNode.ToolTip = row["BASLIK"].ToString() + " kütüphanesini ekle";
childNode.Target = "_new";


node.ChildNodes.Add(childNode);
}
}

Answer

You can set CSSClass of treeview child nodes like

      <asp:TreeView LeafNodeStyle-CssClass="childnode" runat="server">....</asp:TreeView>

then using jquery you get get class and set return false like follow.

      $(".childnode").click(function(){
                 return false;
      })

...same way you can set RootNodeStyle-CssClass, ParentNodeStyle-CssClass class and use jquery to set them...

Comments