TreeView Control In ASP.net
-
Sachin Dubey wrote:
And i have to use object datasource..
So, what is the problem?
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
what shuld be the process flo in this... i never used treeview with datasource i only used with javascript..
-
Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..
Sachin Dubey wrote:
Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..
What is your question ? Do you want to bind the data from database into table or what ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Visit My Latest Article : Beginner's Guide : Exploring IIS 6.0 With ASP.NET
-
Sachin Dubey wrote:
Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..
What is your question ? Do you want to bind the data from database into table or what ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Visit My Latest Article : Beginner's Guide : Exploring IIS 6.0 With ASP.NET
yes i want to bind data from db only but only using objectdatasource.. how can i handel the node click to show subcategories..
-
yes i want to bind data from db only but only using objectdatasource.. how can i handel the node click to show subcategories..
You can't use
ObjectDataSource
here. A tree view supports only data source that implementsIHierarchicalDataSource
.Navaneeth How to use google | Ask smart questions
-
You can't use
ObjectDataSource
here. A tree view supports only data source that implementsIHierarchicalDataSource
.Navaneeth How to use google | Ask smart questions
Is It Any Control like object datasource or anything else...
-
Is It Any Control like object datasource or anything else...
-
Is It Any Control like object datasource or anything else...
Get the result set in a Collection Object and loop through it. 1) First, get the dataset in Businesslayerclass as below:(eg:businessclass name is Employee)
public static Collection <Employee>GetData()
{
Collection<EmployeeData>empcollection = new Collection<EmployeeData>();
foreach (DataRow datarow in dataset1.Table[0].Rows)
{
//Declare the properties and assign the value;
}}
- In UI, call this method as below:
Employee emp = new Employee();
Collection<Employee>empcollection = new Collection<Employee>();
foreach (Employee emp1 in empcollection)
{
TreeNode tn = new TreeNode(emp1.Name)//if you declare the property as Name.
tn.OnPopulateDemand = true;
TreeView1.Nodes.Add(tn);
}Hope this helps. :)
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
-
Get the result set in a Collection Object and loop through it. 1) First, get the dataset in Businesslayerclass as below:(eg:businessclass name is Employee)
public static Collection <Employee>GetData()
{
Collection<EmployeeData>empcollection = new Collection<EmployeeData>();
foreach (DataRow datarow in dataset1.Table[0].Rows)
{
//Declare the properties and assign the value;
}}
- In UI, call this method as below:
Employee emp = new Employee();
Collection<Employee>empcollection = new Collection<Employee>();
foreach (Employee emp1 in empcollection)
{
TreeNode tn = new TreeNode(emp1.Name)//if you declare the property as Name.
tn.OnPopulateDemand = true;
TreeView1.Nodes.Add(tn);
}Hope this helps. :)
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
That comes closer but your code will only add nodes at the root level. This will not give hierarchical structure. To get a hierarchical structure, you should have some mechanism to identify the nodes parent and child nodes. I have answered a similar question a while back. See here[^] if you are interested.
Navaneeth How to use google | Ask smart questions
-
Is It Any Control like object datasource or anything else...
Are you aware about the existence of documentation?[^]. Here is what it says: _The TreeView control can also be bound to data. You can use either of two methods to bind the TreeView control to the appropriate data source type:
- The TreeView control can use any data source control that implements the IHierarchicalDataSource interface, such as an XmlDataSource control or a SiteMapDataSource control. To bind to a data source control, set the DataSourceID property of the TreeView control to the ID value of the data source control. The TreeView control automatically binds to the specified data source control. This is the preferred method to bind to data.
- The TreeView control can also be bound to an XmlDocument object or a DataSet object with relations. To bind to one of these data sources, set the DataSource property of the TreeView control to the data source, and then call the DataBind method.
_
Navaneeth How to use google | Ask smart questions
-
Hi All friends.. I Have 2 tabels for categories and subcategories.. Which i have to show by Treeview control.. i have some restrictions that i cant use javascript. And i have to use object datasource..
Better If you use xml. Create a xml file xtracting data from both the table(Suppose filename is x.xml) <menu type="root" value="HOME" url="~/Accounts/Index1.aspx"> <submenu type="folder" value="Fruits"> <state type="document" url="~/HR/a.aspx" value="Apple"/> <state type="document" url="~/HR/b.aspx" value="Mango"/> <state type="document" url="~/hr/c.aspx" value="Grapes"/> </submenu> </menu> Add a treeview Control on your form page in page_load section paste following codes: In CodeBehindfile XmlDataSource obxlmAdditional = new XmlDataSource(); obxlmAdditional.DataFile = "/x.xml"; treeMenu.DataSource = obxlmAdditional; treeMenu.DataBind();