If i understand you right this would be ur Solution
SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=test;Integrated Security=True");
TreeNode PNode = new TreeNode();
protected void Page_Load(object sender, EventArgs e)
{
BindDataInTreeView();
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
string qry = "insert into Student1 values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')";
SqlCommand cmd = new SqlCommand(qry, con);
cmd.ExecuteNonQuery();
con.Close();
BindDataInTreeView();
}
private void BindDataInTreeView()
{
DataRow dr;
TreeView1.Nodes.Clear();
con.Open();
string qry = "select * from Student1";
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
PNode.CollapseAll();
if (dt.Rows.Count > 0)
{
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
dr = dt.Rows[i];
PNode = new TreeNode(dr["StudentName"].ToString().Trim());
this.TreeView1.Nodes.Add(PNode);
PNode.ExpandAll();
}
}
}