Add usercontrols dynamically inside a GridView - c#

Here's my problem. I am trying to add usercontrols dynamically to different rows of a GridView.
Let me explain the scenario further. Let's say, I have a page where the user can place orders for different kinds of items. The order form for each item is different in layout and code, and has its own usercontrol. There is an "Add More" button, which lets the user add an extra row to the GridView, while the kind of form that gets appended is selected by the dropdown list (see picture below).
What I am trying to do is - have a separate UserControl for each one of these forms, and then have the UserControl added (or maybe I should say "bound") to the GridView. Every time a new row is added, I plan to re-bind the GridView, including rows from above, to maintain all the rows.
The problem is - the main page cannot know what fields there will be inside each individual UserControl (they can be anything, really, and down the road, newer UCs could be added). So my main question is - how do I bind the data to the GridView, when I do not know what to bind? Is there any way to bind the data from inside each UserControl itself?
I hope my problem and question are clear enough. Thanks for helping.

Related

List data in multiple views edit data on click

I'm trying to figure out what design object to use for my forms application.
I want to make a forms application that looks like below image.
I have so far used splitcontainers for the layout and three gridviews with separate DataSources querying the same table but with different where clause for eatch gridview. This works fine but when i click a row in any of the three gridviews i cant have that data show on the right side becaus i can only get data from one datasource on my labels and textfields etc.
I guess that i should use one datasource but in some way have different where clause to each gridview but i've tried it and i only end up with the same data in all of the gridviews.
If it's to complicated to get together i would instead have a new form window apeare with a click of a button. So if i select one row in any of the gridviews and then click edit a new forms window will open for me to edit data in. How can i do that?
Please advice me how i should try to build the application.
For example; Dont use gridviews use this or that instead. Dont use splitcontainers use this instad. Use bindingsources... etc.
I really appreciate any help you can provide

Manage state in MVC4

I have a page with around 20+ controls. Within this page I have a partial View which I am using to create an editable grid. This grid has Add New Row/Remove Row buttons on click of which data entered in the textboxes in grid row gets added to the grid.
Whenever I click these 2 buttons, my page is getting refreshed due to which whatever data is being entered by the user in the 20+ controls of main page is lost.
I have tried hopelessly searching for solutions quite some time, but still trying my luck out here. Any ideas are appreciated.
Well I recommend you to use full jquery mechanisms to add or remove rows. You can easily add or remove HTML elements. All you have to care about is to maintain the numbering system. I suggest you to use a view model that contains a list of objects that you need to add or remove. At first render it normally by providing list of objects (from database or other source, if required). After this define your add and remove buttons to type button and play with jquery to add remove table rows or even divs. After adding or removing required element, reorganize your numbering. At submit you can use either full postback or ajax postback. If Any confusion, let me know.

Navigation grid inside of a FormView

We have a list of elements we use to drive a form view. Typically the resultset is between 5-15 records. Right now in the form view we have the typical first/prior/next/last for navigation. The problem is that sometimes the user needs to go directly to a specific record to edit it. The records here are job tasks that have some pretty short descriptions.
The idea was proposed to put a gridview inside of the formview that lists all of the records for that form, and a user can just select view or edit on that record and it will navigate directly to that record and put it into the proper mode. We could put this outside the form view as well, that doesn't really matter.
The question is, regardless of the dirving force, how to I tell the formview to go to record X driven from something like an external grid.
I know that the formview has the DataKeyNames field but is there a way to say "Go to record who's PK is 17" given that it's in the current dataset for the formview?
If so, does anyone have any sample C# code for it? I know we could just populate the existing formview with a single record, but we also want to keep the normal navigation buttons in place as well, in the event as well (sometimes there's cases where there's hundreds of job tasks, in which case we'd supress the grid view -- sounds wrong but there's more to the business case).
This short solution was to embed the grid in the FormView ItemTemplate and reference the same data source for both.
To made the row editable, you need a simple callback for RowDataBound on the grid in which you will retrive the link button (or whatever control you're using to trigger the edit) and then set the command argument to the rowindex. After that, you need to have the callback for the link button (or trigger) that wil retrieve the command argument (again the row index) and then set the FormView PageIndex to that value, and then set the ChangeMode for the FormView to FormViewMode.Edit.
So to recap, for read only view it's a grid with all of the items, but when handle the edit or insert, you get the traditional form view.

how to copy data from Form to another Form using C#?

I have got 2 Forms. The first one contain Data Grid View 1 and the second one contains Data Grid View 2 and Button. I want code, using C#, that when the user clicks on Button,
the data in the Data Grid View 2 is taken and displayed in Data Grid View 1. Can anyone can tell me how to do this in details please.
Depending on what you're really trying to do, I would suggest to make use of the BindingSource class in both your forms, and bind them according to what you need with your DataGridviews, then expose your BindingSource.DataSource through a Form property which will allow you to get and set the datasource outside of your Form, hence allowing you to change or update your [DataGridView.DataSource]4 property through this Form's property.

C# gridview nested in repeater update

My current situation is to display an unknown number of Plantypes and within those Plantypes display a list of Participants(also unknown number), the participants have a textbox and a dropdown that is editable (you can't edit the individual rows, there is one update that does a bit of validation then updates all rows.)
I currently have a gridview nested withing a repeater, the repeater displays the Plan in a label and OnItemDataBound I call a method to populate the gridviews. It looks great, but I can't figure out how to save all the data at once. I'm not opposed to handling this a different way, as in loose the gridview and or repeater, if someone has a better idea.
This is C# and framework 2.0...there is no sorting or paging on the gridviews...just some links and the fields to update.
thanks in advance,
Padawan
HTTP is stateless. Since a user physically can only update one record at a time you should implement some way to save as the user goes. This can be a simple as having a row focus and row blur events and do the saves using AJAX on blur(unfocus). Maybe make is modal as they edit so they cannot leave the page without saving.

Categories

Resources