What is the best method to display repeating data with slightly different controls or sub data? For example displaying an expanded list of questions and answers. Some questions will have answers, some will not. Some button controls would show for some items while not for others.
In classic ASP I've used XML/XSL quite effectively for displaying data in this manner. In .NET I've used functions being called from a label with the HTML writer class to render controls dynamically and nested list views that would bind or not depending on existing data.
I know I could also use XSL with .NET but my question is - is there a better method of displaying data this way? Inline IIf's and functions being called from the front end doesn't seem very clean.
I think the ListView would work in your situation:
http://blogs.msdn.com/mikeormond/archive/2008/01/23/some-asp-net-3-5-listview-control-examples.aspx
http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx
You have the ability to group items in different layouts using the ItemTemplates and you can also tap into the event handlers when loading the data.
EDIT:
You may be able to do it this way dynamically, but it's tricky with the ID's:
http://blogs.msdn.com/mikeormond/archive/2008/07/26/dynamically-loading-listview-templates.aspx
Or you could simply create a table composite control and build it up dynamically yourself...
Related
I am looking for a general, reusable UI pattern I can use for editing the content of dropdown lists in my MVC3 app. That is, some of the Id-Name pairs used to populate dropdowns for edit views exist only for this purpose, and have no dedicated controller-view setup themselves. E.g. Industry and Sector for course modules. Each list is only an Id-Name structure, but Sector has an IndustryId value as well.
Now I really don't want to use the standard scaffolded views for these, i.e. create,edit, and list with links, but I can't help wondering how best to improve on these. Should I bind each list to an editor that just renders a an EditorFor textbox for each item in the list, with jQuery to add a new item or delete an item? is there some established way of doing this?
NOTE: This is not about loading a dropdown list. It's about loading the values for a dropdown list into a view for editing them, to control what appears in the dropdown list when it loads by whatever means.
I don't know if there's a pattern per se, but we deal with this sort of thing as well (dozens of lookup tables with the same structure) and we use simple pages with a jqGrid. The editing is live in the sense that changing a row causes an Ajax call to the controller to modify the lookup value itself. Works fairly well. We ended up having a dedicated view for each of the editable lookup tables (not all of them are) but it would have been simple enough to use the same view, controller and client-side script for all of them.
You can use jQuery, and jQuery UI to customise your dropDown lists
I'm sure I'm missing something obvious here.
I have a about twenty data-bound GridViews, each of which share some common features. Let's say they're all lists of people, and every one starts with about 10 columns which are complex linkButtons with hovers etc, they're all the same. The remainder of these grids, which are extremely wide, consist of completely different columns; it's just the first 10 (of about 100) columns which are duplicated.
Hence I have this chunk of code which handles those 10 database columns and renders that html out, using 10 Eval() statements etc. It's the same code in each GridView, it's repeated 20 times over and that's obviously not cool.
I can't just chuck it in a user control or a custom control because I need the GridView to do the column headers and all that stuff. I can of course put a user control in for one column and render everything I want that way ("eval" works nested like that), but it doesn't give me the column headers, which are also complex.
So that's the question: is there any way I can break out of a templated GridView control to abstract this repeated code? I almost want a sort of server-side include or pre-processed thing, as I just need to repeat the text really, but I need to do it before asp.net tries to compile it. I could use a custom control to render any HTML I like, but that doesn't solve the problem as it's asp.net code I need to generate, not HTML.
Can't you subclass from Gridview and implement the common functionality for all the 10 gridviews there and then have further subclasses that implement the specific functionality for the specific gridviews? I've done this successfully with Pages (the most base class had authentication logic that all subclasses inherited)
I am trying to create a form that is made up of controls with values that represent an entity with multiple child entities.
The form will represent a product with multiple properties where the user will then be able to create options with multiple properties which in turn be able to create multiple option-items with multiple properties.
My question is what is the best approach? Can i use ajax to avoid postbacks and having to rewrite the controls to the page? If i dynamically add the controls in the form of table rows or grid rows will the data/control values be available in the code-behind when i submit?
This is an age old question.. the last time i had to do this was .Net 2.0, pre-ajax (for me) and i was forced to recreate all the controls on each post back. thanks!
If I'm understanding your question correctly, you want to dynamically change form elements depending on some kind of selection criteria without refreshing the page? Javascript can do this for you. If your elements rely on data from somewhere, such as options for a select menu, then yes you will have to use an ajax request to populate those. If they are static options, then pure javascript will work for you. And though the source won't indicate your generated elements, they will indeed be available for a submit. I hope this helps.
I would like to create a general form so that it can deal with creation/read/update of an entity. When creating an entity, it may only contain a subset of all fields; when updating the entity, it may contain a different subset of fields; and when reading the entity, none of the fields are editable. Anyone with experience in designing such a form in Flex? Thanks in advance.
I was frustrated with the quality of the flex forms as well, especially managing the validation, so I wrote my own form control. It's a bit haphazard and buggy at times so it's not ready for sharing, but I'll cover the ideas:
Separated into a layout part and a data part, matched by keys. Both are basically combinations of AS3 Objects/Arrays containing the properties I need.
Describe all the possible visible elements in the layout, the validators needed, visual properties, labels ,etc... Every element in the layout is an Object in an Array. The primary array is ordered and displayed via a VBox. Any nested arrays are displayed in a nested HBox (e.g., useful for radio options).
The data part of the form is where you can set initial values, "editable" properties, "model" properties (for combo boxes), things like that. The data structure is an Object hash where the keys map to elements in the layout. If an entry from the layout does not exist in the data definition, it does not appear. This allows you to easily hide sections you don't want to show.
Has an errors sections where validation or server errors can be displayed.
Has a collect function that collects all the data into an object hash.
Has a validate function to control when the validators are triggered.
Non editable fields show up as labels.
Basically I've implemented my own "Form" control, and each entry in the layout (when displayed) becomes a custom "FormItem" control that will be whatever type the layout described. ("text","combo","heading",...)
Hard to describe without visual examples and some code, but that's the basic idea. You're on the right track thinking that you need your own control. There's too much hand-holding required for the generic forms, and lots of redundant code.
Check out Rocket Framework .. you gonna love it..
Want to automate winforms? not just CRUD, this help creating any type of winforms controls. The Rocket Framework for WinForm (using .net c# 4 ) provides a set of easily utilizable generic library to seemlessly develop 'form based' application/ control / custom controls for .Net.
I'm currently building a Gridview that has expandable rows. Each row contains a dynamically created Panel of Form elements. Right now, I have a javascript function that expands (or in my case, makes visible) the panel when an Image is clicked on the Gridview row.
My question is... is there a more efficient way of doing this. Instead of pulling all my data to begin with and building each new row as I Databind, is there a way to simple create the row with the Panel full of textboxes and dropdownlists on the fly when the user clicks the Expand button?"
I'd like to limit the server calls by doing it that way instead of how I'm currently doing it, looping through every row and creating a new panel with form elements and inserting that into a row that is hidden.
Actually, it isn't performing badly since my original SQL query can populate every single row and I have enabled paging on the Gridview. I'm just wondering if they can be built on the fly using PageMethods or some sort of JSON/AJAX solution. I haven't seen anything, but... worth a try in searching for it.
you can override the RowdataBound event, and than add whatever controls you want based on what data goes in the cell.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
Personally trying to create the data on the fly would most likely result in a slower user experience.
When I do things like what you are describing I typically use Repeaters, that way I can do a template layout that simply defines all of the needed elements right away, and it handles the binding actions.
Otherwise, I would imagine that your way isn't performing too slowly as it is.
Actually worked this recently into an AJAX Handler returning the form structure. It's on demand, and works well. Simply call $ajax via jQuery, return an HTML structure, inject into DIV. It's a bit limiting on actual functionality, so be careful.