I need to populate an ASP.NET menu control with hierarchical structure with menu items that can be constantly changed, from a database (categories with n levels of sub categories).
There are some approaches for that and I would like to hear which one is the most efficient one.
I have those in mind:
Retrieving data from database and converting it to xml then transforming it with customized XSLT file and binding it to Menu control
Retrieving data from database and while looping through (recursive), inserting menu items and children to the menu control
SQL Site Map Provider (thanks to Made4Print)
Something else?
The ASP.NET Menu Control can use a .SiteMap file through a SiteMapDataSource.
You can implement your own SiteMapProvider, this way you can have your SiteMap heirarchy within your database and wireup the same components making things more dyanamic.
Here is an example: http://weblogs.asp.net/scottgu/archive/2006/01/11/435108.aspx
HTH
I agree with Marc. You could then package everything inside a server-control for reusability. Converting everything into XML and then using XSLT to somehow "convert" it back seems an overhead to me.
If you want to do this, I would definitely recommend option 2, since it contains one level of transformation less than option 1. If you already loop through the menu items and their hiearchies, you might as well build up the menu items and subitems directly - I don't see any big benefit from taking a detour over XML and then through XSLT into a menu structure, really.
Marc
PS: Option 3 (the SQL Sitemap provider) also sounds like a really good idea, if the site map structure and options are good enough for you (they usually should be). I would probably try that option first, and go from there.
Related
I want to bind an ObservableCollection to an XML file. Before the multiple replies of
You should bind your DataGrid, ComboBox, etc.. directly to the XML file
Please note that the ObservableCollection already exists and is already being bound to DataGrid, ComboBox etc... Re-writing all that code doesn't sound like fun at all to me. Although every search I do about binding an XML file to a ObservableCollection returns binding object directly the XML file.
Yes I know I could manually do the add, update, and delete myself but was hoping to not have to do that.
manually do the add, update, and delete myself
Please don't delete yourself. ;-)
Xml node processing is a complex process and does not easily lend itself to such a scenario as adding and deleting from a string list which is what the question is patterning itself off of....
At some point code is needed as a go between, the visual and storage, to facilitate the process of managing the xml structure as adds and deletes are done.
Microsoft Blend has support for binding straight to XML. Perhaps you could add some design time data to the form in Blend, and see what it generates. It might give you some ideas.
I'm trying to design my C# winform application with a very generalized function to automatically go through all of the form elements and save their states/values in a text file so that I can load it later. I want it to be very generalized so that it'll be a cinch to reuse this code in future projects, as it wouldn't be heavily tied down to the specifics.
The form elements I want to save are text boxes, combo boxes, data grid views, list boxes and that's about it. I want to save their values and everything about them.
One way that I was going about it was to go through every possible form element and then detect eachs type, and then create the corresponding c# code to re-create its value ('tboxmine.value="blue elephant"'), and then writing the code to a file, so that I could load the code from the file and execute it using the CSCcompiler. My code so far doesn't seem to be working correctly and I'm having my doubts that this compiler is actually running the code inside my application (I think it's possibly creating a new thread?), and it just seems like there's probably a far more straightforward relatively standard way of doing this.
This seems a bit like the reverse "best practice" approach. If you dont't know about databinding I suggest you look into that.
Basically you create classes to represent your data and use databinding to associate controls with your objects. The controls will automatically show the right value and allow the user to change it. If the user has changed the value, your object gets automatically updated.
To save the data, you would use some kind of serialization to store your objects in a file. When loading, you let the Serializer rebuilt your class structure and (best case) you are good to go.
This is not exactly what you asked for, but I think it is something you could use well ;-)
N.B.: Not the complete state of the control is saved. e.g. in a Textbox your text would be saved but the BackColor won't.
To get you started look into this tutorial: http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial
I'm working on a web app in ASP.NET MVC 3 using the Razor HTML 5 engine and C#. The client wants something pretty complex and I would like to know if there is any examples out on the web that might show me how to begin setting this up. Here's what they are looking for:
I have a very large SQL database (25,000 rows). They want to be able to select the data using three different views on the same page.
The first will be a tree and using similarities in certain columns of the table will be how the tree is broken in to sections.
The second will be a grid. This will be just one entire list of the everything in the database that you can scroll through. Of course there has to be some sort of virtual scrolling because loading 25,000 rows rather quickly isn't going to happen.
The third will be a search box where you can type in the code and select it that way.
All three of these need to be linked so that when you type a code in the search box it will select it in the grid and in the tree. If you select it in the tree then it will be selected in the grid, and if you select it in the grid then it will be selected in the tree.
They also want me to remember the last selection when you navigate away and be able to type a code n on a different page and go directly to this page with the item you typed selected. Therefore, I need to be able to use MVC's capabilities to establish a hyper link for every item in the list (I assume that would be the way to do this)
This is honestly the first time I've worked with ASP.net MVC and I feel like I may have bitten off more than I can chew with this project so any help would be greatly appreciated!
They would rather it if I didn't need to include any extra dll's so if there is a way to do this without third party tools that would be even better, but at this point I'm just looking for anything.
A few random ideas/thoughts about this:
This is kind of a big project as your first MVC app - hopefully you have some experience with HTML/Javascript/jQuery since it's going to require a fair amount of glue code to make everything work together. There is no "here, do this" solution.
There are a bunch of different free/open source projects for treeviews and grids. I've used jqGrid for a number of projects - it works well. It has a decent API and is fairly configurable (although it may take some digging to find the example code you need).
For a treeview, you can try jsTree. I haven't worked with it, though.
I'd suggest starting with just the treeview, or just the grid and get it working first. Then add the other control and get it working. Then add the search. Finally, I'd work on getting everything to work together.
To handle navigating to a specific selection, you can pull information off the query string from Javascript.
Realize that most of this is going to be happening in Javascript on the client side, not much server side.
I need to create a UI that will load from an xml file information that will determine the look of the UI. Simply put, the xml file will determine the locations of a bunch of buttons in a grid like interface. Im thinking that it could be built with a single Panel container with a variable number (depending on the info given in the xml file) of table layout panels. Each table layout panel will have a variable number of rows/columns (also dependant on the info given in the xml file).
I have the creation and mapping of controls working fine, however proper sizing of everything continues to be a challenge.
Are there other controls out there better suited for mapping out dynamic interfaces?
Any tips/tricks/pitfalls?
Use WPF (as mentioned) or use Gtk# (see website)
Also, a wellknown trick with Winforms is to make ample use of datagrids bound to Datatables (or DataSets in general). Even if your backend isn't actually a ADO.Net provider you can dynamically create DataTables (adding columns with proper datatypes). The datagrid will know how to make these columns editable/sortable etc.
$0.02
I'm developing an C# .NET Windows Form application that 'll manage a hierarchical tree-view structure. (I have a single SQL table with a hierarchyid column. The data set is small ~300 rows/nodes at the moment, but is bound to grow large eventually)
After I exit the application, I want to be able to restart it with the last modified state. I understand I can do this by serializing it to XML.
However, I'm trying to find a method by which the treeview could be generated directly from the table at run time, using the hierarchy id column.
After Googling around, I've found some others who wish to the same, but unfortunately I've found no solutions. Is there a good way to do this?
Thanks.
Look for IHierarchicalEnumerable, HierarchicalDataSourceControl and HierarchicalDataSourceView. Thats exactly what are you looking for.