Hi im having treeview with checkbox and 1 submit button it is taking values from database.
now if i check the checkbox and click the submit button it should display the selected node in the textbox.....
here is my treeview code
public void Load_tree()
{
DataSet PrSet = PDataset("SELECT * FROM tbl_saleschannelhierarchyconfig");
TreeView1.Nodes.Clear();
foreach (DataRow dr in PrSet.Tables[0].Rows)
{
if ((int)dr["ParentID"] == 0)
{
TreeNode tnParent = new TreeNode();
tnParent.Text = dr["Parent"].ToString();
string value = dr["ParentID"].ToString();
//tnParent.Text = dr["SalesChannelName"].ToString(); - if u use this instead of the previous two lines, then "kmart" will be the parent. else "root" will be the parent.
//string value = dr["SalesChannelConfigID"].ToString();
tnParent.Expand();
TreeView1.Nodes.Add(tnParent);
FillChild(tnParent, value);
}
}
}
public int FillChild(TreeNode parent, string SalesChannelConfigID)
{
DataSet ds = PDataset("SELECT * FROM tbl_saleschannelhierarchyconfig WHERE ParentID =" + SalesChannelConfigID);
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode child = new TreeNode();
child.Text = dr["SalesChannelName"].ToString().Trim();
string temp = dr["SalesChannelConfigID"].ToString();
child.Collapse();
parent.ChildNodes.Add(child);
FillChild(child, temp);
}
return 0;
}
else
{
return 0;
}
and button click code
protected void Button1_Click(object sender, EventArgs e)
{
txtRetailCustomerGroup.Text = TreeView1.SelectedNode.Parent.ToString();
}
it is showing this exception
"Object reference not set to an instance of an object."
can any1 help me??