Refresh TreeView after insert/update/delete ?

Wrong solution :

DataBind() BEFORE close()

        TreeView1.DataBind()

        con.Close()

Right solution:

In btnListtAdd_Click :

  To get the ID

        Dim lastID As String = “Select @@Identity”

        Dim getID As Integer

        ‘this is to get last ID

        cmd.CommandText = lastID

        getID = cmd.ExecuteScalar()

        PopulateNodesAdd(getID)

        con.Close()

PopulateNodesAdd(getID):

        Dim tn As New TreeNode()

        tn.Text = TextBoxChild.Text.ToString()

        tn.Value = pID

        tn.Target = “_blank”.ToString()

        TreeView1.SelectedNode.ChildNodes.Add(tn)

        TreeView1.SelectedNode.Expand()

btnListModify_Click :

        ‘Reflect changes

        TreeView1.SelectedNode.Text = TextBoxParent.Text

        con.Close()

btnListDelete_Click :

        PopulateNodesDelete()

        con.Close()

 

PopulateNodesDelete() :

 

        Dim delnod, nod As New TreeNode

        delnod = TreeView1.SelectedNode()

        nod = TreeView1.SelectedNode.Parent()

        delnod.Parent.ChildNodes.Remove(delnod)

 

 

Advertisements

About Ahmed

Software craftsman, programmer, developer, system/business analyst, DBA and PM.
This entry was posted in Databases, Programming, SQL-Server, VB.NET and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s