Hello,
I am using Asp.net Tree View i have bind data from database, now i want search Nodes functionality and Drag & Drop functionality which update data in database on drag and drop? Please provide me a example or sample code.
This is my Code :
<asp:TreeView ID="Treiew" ShowLines="true" runat="server" OnSelectedNodeChanged="Treiew_SelectedNodeChanged" OnTreeNodePopulate="Treiew_TreeNodePopulate">
<LevelStyles>
<asp:TreeNodeStyle ChildNodesPadding="10" Font-Bold="true" Font-Size="12pt" ForeColor="DarkGreen" />
<asp:TreeNodeStyle ChildNodesPadding="5" Font-Bold="true" Font-Size="10pt" />
<asp:TreeNodeStyle ChildNodesPadding="5" Font-Size="10pt" Font-Underline="true" />
<asp:TreeNodeStyle ChildNodesPadding="10" Font-Size="8pt" />
</LevelStyles>
</asp:TreeView>
protected void Page_Load(object sender, EventArgs e)
{
sConn = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
if (!Page.IsPostBack)
{
PopulateRootLevel();
Treiew.SelectedNodeStyle.ForeColor = Color.Red;
}
}
private void PopulateRootLevel()
{
SqlConnection objConn = new SqlConnection(sConn);
SqlCommand objCommand = new SqlCommand(("select ID,Title,(select count(*) FROM abccc " + "WHERE ParentID=sc.ID) childnodecount FROM abccc sc where ParentID=0"), objConn);
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, Treiew.Nodes);
}
private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Text = dr["Title"].ToString();
tn.Value = dr["ID"].ToString();
nodes.Add(tn);
tn.PopulateOnDemand = (int.Parse(dr["childnodecount"].ToString()) > 0);
}
}
private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection(sConn);
SqlCommand objCommand = new SqlCommand(("select ID,Title,(select count(*) FROM abccc " + "WHERE ParentID=sc.ID) childnodecount FROM abccc sc where ParentID=@ParentID"), objConn);
objCommand.Parameters.Add("@ParentID", SqlDbType.Int).Value = parentid;
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);
}
protected void Treiew_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
PopulateSubLevel(int.Parse(e.Node.Value), e.Node);
}
protected void Treiew_SelectedNodeChanged(object sender, EventArgs e)
{
textbox.Text = Treiew.SelectedNode.Value;
}