?
Solved

(ASP.Net - C#) how can I get the checked value from the check box in tree view?

Posted on 2010-01-12
4
Medium Priority
?
697 Views
Last Modified: 2012-05-08
Dear all, I'd like to ask, how can I get the checked value from the check box in tree view in ASP.net C#, and if i only check the child node, how can i get the corresponding root value as well?

Thank u very much!
0
Comment
Question by:rajatop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 26294807
where and when you want to get this checked value?
If you are using TreeNodeCheckChanged event then you can get the parent by:
e.Node.Parent.

The idea is get hold of the node and then access its Parent Property.
0
 

Author Comment

by:rajatop
ID: 26300022
this is the code in View.aspx:
<asp:TreeView ID="trvTable" runat="server" ShowCheckBoxes="All" onclick="SelectAllChildNodes()">
                    </asp:TreeView>


this is my code in code behind page:
private void getTableTree()
    {
        tmp = commonfunction.getTemp();

            SqlConnection SqlCon = new SqlConnection("server=" + tmp.ServerName + ";Trusted_Connection=Yes;");
            SqlCon.Open();
            SqlCommand cmd = new SqlCommand();
            string tableName = "";
            SqlDataReader rdr;

            string sql = "SELECT * FROM " + tmp.DatabaseName + ".sys.tables";
            cmd = SqlCon.CreateCommand();
            cmd.Connection = SqlCon;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sql;
            rdr = cmd.ExecuteReader();
           
            while (rdr.Read())
            {
                tableName = rdr.GetString(0);
                TreeNode masterNode = new TreeNode((string)tableName);
                trvTable.Nodes.Add(masterNode);
                getFieldTree(tableName, masterNode);
                counter++;
            }

            hidCounter.Value = Convert.ToString(counter);
           
        }


  private void getFieldTree(string TableName, TreeNode masterNode)
    {
        tmp = commonfunction.getTemp();
            SqlConnection connect = new SqlConnection("server=" + tmp.ServerName + ";Initial Catalog=" + tmp.DatabaseName + ";Trusted_Connection=Yes;");

            string strSQL = "SELECT * FROM [" + TableName + "]";
            SqlDataAdapter objDataAdapter = new SqlDataAdapter(strSQL, connect);
            connect.Open();
            DataSet objDataSet = new DataSet();

            objDataAdapter.Fill(objDataSet, TableName);
            objDataAdapter.Dispose();

            DataTable dt = objDataSet.Tables[0];
            foreach (DataColumn dc in dt.Columns)
            {
                TreeNode childNode = new TreeNode(Convert.ToString(dc.ColumnName));
               
                masterNode.ChildNodes.Add(childNode);

            }

           
        }
could u give me the sample, after we check the check box, how can we get the checked value? Thank u so much!
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 26517622
--->could u give me the sample, after we check the check box, how can we get the checked value? Thank u so much!

modify your TreeView markup like below:

<asp:TreeView ID="trvTable" runat="server" ShowCheckBoxes="All"
        ontreenodecheckchanged="trvTable_TreeNodeCheckChanged">

code-behind:
protected void trvTable_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
    {
        if (e.Node.Checked)
        {
            Response.Write(e.Node.Text + " Checked");
        }
        else
        {
            Response.Write(e.Node.Text + " UnChecked");
        }
    }

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question