I want to get checkbox checked value from Treeview.
I bind the data from oracle database on Treeview.
Code:
protected void Page_Load(object sender, EventArgs e)
{
fill_Tree2();
}
void fill_Tree2()
{
DataSet PrSet = PDataset("Select * from Activity_Parent");
TreeView1.Nodes.Clear();
foreach (DataRow dr in PrSet.Tables[0].Rows)
{
TreeNode tnParent = new TreeNode();
tnParent.CollapseAll();
tnParent.Text = dr[1].ToString();
tnParent.Value = dr[0].ToString();
tnParent.ToolTip = "Click to get Child";
TreeView1.Nodes.Add(tnParent);
FillChild(tnParent, tnParent.Value);
}
}
public void FillChild(TreeNode parent, string ParentId)
{
DataSet ds = PDataset("Select * from Activity_child where Activity_ID =" + ParentId);
parent.ChildNodes.Clear();
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode child = new TreeNode();
child.Text = dr["ActivityName"].ToString().Trim();
child.Value = dr["ActivityChild_ID"].ToString().Trim();
parent.ChildNodes.Add(child);
}
}
protected DataSet PDataset(string Select_Statement)
{
OleDbConnection DbConnection = new OleDbConnection("Provider=MSDAORA.SNIDB;Data Source=SNIDB;User ID=AZRAAR;Password=AZRAAR");
OleDbDataAdapter ad = new OleDbDataAdapter(Select_Statement, DbConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
ViewState["ds"] = ds;
return ds;
}
In the below Button click event,I tried but it is not working
protected void btnGet_Click(object sender, EventArgs e)
{
DataSet ds1= (DataSet)ViewState["ds"];
foreach (DataRow dr in ds1.Tables[0].Rows)
{
TreeNode tn = new TreeNode();
if (tn.Checked == true)
{
Response.Write(tn.Text);
}
tn.Text = dr["ActivityName"].ToString();
TreeView1.Nodes.Add(tn);
}
}
}
In the below image if I select Checkbox HR Activity1, Developer Activity3 etc.,
I want to get that value
Any ideas? Thanks in advance