| |

VerySource

 Forgot password?
 Register
Search
View: 797|Reply: 4

Also about the checkbox in treeview

[Copy link]

2

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-16 23:00:01
| Show all posts |Read mode
I want to ask, how does the text value of the multi-select box I use enter the database? I can only enter one. I want to ask how to loop, I don't understand, thank you ~~
code show as below:
 if (TreeView1.CheckedNodes.Count> 0)
        {
            foreach (TreeNode tn in TreeView1.CheckedNodes)
            {
              if (tn.Checked == true)
                {

                    addtext = tn.Text;
                }

            }

        }
        string EIPConnectionString = ConfigurationSettings.AppSettings ["EIPConnectionString"]. ToString ();
        SqlConnection conn = new SqlConnection (EIPConnectionString);
        conn.Open ();
        SqlCommand cmd1 = new SqlCommand ("select KindID, ParentID from sys_menu where Context = '" + addtext + "'", conn);
        SqlDataReader readr = cmd1.ExecuteReader ();
       while (readr.Read ())
        {
          // pid = readr ["pid"]. ToString ();

            kindid = readr ["KindID"]. ToString ();
            preatenid = readr ["ParentID"]. ToString ();
        }

        readr.Close ();
        id = Request ["groupid"]. ToString ();
        SqlCommand cmd = new SqlCommand ("insert into groups_menu (KindID, ParentID, id) values ​​('" + kindid + "', '" + preatenid + "', '" + id + "')", conn);
        cmd.ExecuteNonQuery ();
        Response.Write ("<script> window.alert ('Send successfully!'); </ Script>");
        conn.Close ();
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-22 18:30:01
| Show all posts
ArrayList arr = new ArrayList();
            
            if (TreeView1.CheckedNodes.Count> 0)
            {
                foreach (TreeNode node in TreeView1.Nodes)
                {
                    if (node.Checked == true)
                    {
                        arr.Add(node.Text);
                    }
                }
            }

            string addtext = null;
            string EIPConnectionString = ConfigurationSettings.AppSettings["EIPConnectionString"].ToString();
            SqlConnection conn = new SqlConnection(EIPConnectionString);
            conn.Open();
            for (int i = 0; i <arr.Count; i++)
            {
                addtext = arr[i].ToString();
                SqlCommand cmd1 = new SqlCommand("select KindID,ParentID from sys_menu where Context='" + addtext + "'", conn);
                SqlDataReader readr = cmd1.ExecuteReader();
                while (readr.Read())
                {
                    // pid = readr["pid"].ToString();

                    kindid = readr["KindID"].ToString();
                    preatenid = readr["ParentID"].ToString();
                }

                readr.Close();
                id = Request["groupid"].ToString();
                SqlCommand cmd = new SqlCommand("insert into groups_menu(KindID,ParentID,id)values('" + kindid + "','" + preatenid + "','" + id + "')", conn);
                cmd.ExecuteNonQuery();
            }
            
            Response.Write("<script>window.alert('Sent successfully!');</script>");
            conn.Close();
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

Post time: 2020-6-24 17:45:01
| Show all posts
TreeView also needs to traverse child nodes
Reply

Use magic Report

2

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-10 18:45:01
| Show all posts
Solved, thank you very much
Reply

Use magic Report

0

Threads

2

Posts

1.00

Credits

Newbie

Rank: 1

Credits
1.00

 China

Post time: 2020-8-12 02:15:03
| Show all posts
Reply

Use magic Report

0

Threads

2

Posts

1.00

Credits

Newbie

Rank: 1

Credits
1.00

 China

Post time: 2020-8-12 02:30:01
| Show all posts
Brother, I don’t know how to do that. I can only enter one value. I don’t know how to add all the selected checkbox items to the database. Could you please send the code? Thank you, let me refer to it. under
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list