Click here to Skip to main content
16,021,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am developing a project in which I am having a treeview and it is populated from the database, I want to insert the checked item in treeview to database after clicking a button, I am not getting how to insert the checked item in tree view to database.My code in button click event looks like this. Can any one help me...its very urgent
C#
protected void btn1_Click(object sender, EventArgs e) 
{ 
     SqlConnection con = new SqlConnection("Data Source=GAYATHRI\SQLEXPRESS;Initial      Catalog=VOY_SERVICES1;Integrated Security=True"); con.Open();
 
    foreach (TreeNode tnode in TreeView1.CheckedNodes)
    {
 

        if (tnode.Checked == true)
        {
 
            string strTreeValue;
            strTreeValue = tnode.Value;
            SqlCommand com = new SqlCommand("insert into treeview_select(subdisease_name) values(@name)", con);
 
            com.Parameters.AddWithValue("@name", strTreeValue);
            com.ExecuteNonQuery();
            con.Close();
 
        }
    }
}



with the help of brk points i came to know tat object of type "Treenode" in foreach loop is not getting created. please help with the code.



thnx
Posted
Updated 18-May-12 18:55pm
v2
Comments
[no name] 19-May-12 0:56am    
Code block added
shabadiveda 19-May-12 2:49am    
Thnx for the reply....I referred the links,but i am having check boxes in leaf nodes, once the user checks nodes and click on submit button the selected items in treeview has to be inserted to database.help me on that..

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900