Bind an ASP.NET TreeView to SqlDataSource using an XML query - asp.net

Is it possible to use a SQL query that returns XML, in order to bind a TreeView control to SQL data? In other words, I would like to set up a query that presents table data as hieracrhical XML, and bind this XML to the TreeView.

Are you assuming to bind TreeView to XmlDataSource (XmlHierarchicalDataSourceView)?
You can implement your own IHierarchicalDataSource and HierarchicalDataSourceView for that. I thinks this solution would be better than returning XML from DB.

Related

Why is datasource handling in query different from handling it in a form?

I am trying to rewrite some form to the lisp page template. In a list page you must use query as a datasource. I have datasource structure in previous (without list page template) and a new one with list page template. But I am now facing a fact that handling datasource in form is different than handling it in a query.
Can someone explayin why it is done this way and how to make a query so there will be almost no difference between datasource before and after using list page template?
For example I have DSs Object, Sub-Object1, Sub-Object2.
Sub-Object1 have a jointSource Object in properties with exist joint and Sub-Object1 have jointSource Object with Inner Join.
Is there some way to set this in Query DS properties or I must add
datasource to datasource and link in more manually.
Well mayby because a form need more information than query?
If you do have a query already.you can drag it to your form as a datasource.
See http://msdn.microsoft.com/en-us/library/gg844014.aspx
The same effect as a datasource with join type in properties can be done on query by using related datasources. So on the query the structure will be more readable than structure on normal form datasources.

How to access data in EntityDataSource programmatically

I have an EntityDataSource bound to many filters used by gridview data, I want to have access to the entities that was selected be the EntityDataSource to be able to export them in xml for example, how can I do that?
You get access to result of query executed in EntityDataSource by handling its Selected event and accessing Results of EntityDataSourceSelectedEventArgs.

Read a record via code behind for a sqldatasource

suppose i open a sqldatasource for binding on listview.
I would like also to read a field on first record for print it.
How can i access to my sqldatasource from code behind ?
If I where you I would use (typeBeingBound)((ListViewDataItem)e.Item).DataItem in the listView_ItemDataboundEvent.

Can I specify a Stored Procedure in my LinqDataSource?

I have a Listview that I want to read the results of a Stored procedure. I have created the DBML object with the table and the stored procedure. When I configure my LinqDataSource on the page I cannot specify the SProc - only the Table. Or do I need to do it in the Listview ?
Thanks
Use a custom expression. See section "Using the Selecting Event"
http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx

LINQDataSource - Query Multiple Tables?

I have a database and I've created a DBML Linq-to-SQL file to represent this database. I've created a new aspx page and dropped a linqdatasource and a formview control onto it. When I configure the linqdatasource it gives me the choice only to select * from one table...but I want to pull from multiple tables. e.g. I have tables like simple_person, simple_address, simple_phone, and I want to pull from all of them. How can I accomplish this?
Use a custom query
http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx
See: Using the <asp:LinqDataSource> Selecting Event

Resources