Advice on dynamically generating list - c#

I'm new to coding in ASP, so your patience with me is appreciated.
I've built a user access request form which is working, however I now need to add a permissions section to it.
What this entails is 5 text boxes per row, but have it start with just one blank row, then if they fill in a row, another blank one appears below it.
Then when a button is clicked, the values are uploaded to my database.
This will also need to be populated if a user that already has access returns to the page.
Can this be done?
notes:
I'm using the EntityFramework, in .NET 4, with C#

maybe put a button to add new row

Related

How to get my dynamic generated controls value in asp.net C#

I have gone through many articles and similar kind of stack over flow questions. Almost I spend more than a day trying to find the solution, all goes in vain.
First I should tell you what I am trying to make.
There a simple grid having a text box currently
Similar to this article
So when I put some value to text box it generate these text boxes and checkbox within that row.(image related to above description)
There are events firing when text box value get changed , second when add new row is clicked.(Currently ignore delete button event).
What I earlier planned was like this, create controls in every postback,I have saved first row text box values in a viewstate. I create these dynamic controls in grid-row-bound function. So I create no of controls as according to value in viewstate stored value.
I thinked that on event function call I will first store the value of current controls then recreate all controls with same id and put back the value.So problem I am facing is that I can't find my controls on event fire. You can see in these two pic what happening because of that 1st pic 2nd pic.
If you want to see the code , please comment of which sections you want to see the code or full code
Here the link to the code click here

ASP.NET Code behind form rows

I'm trying add multiple items to a database table. I've created a form that will allow the user to add more form rows which include a dropdown and multiple input fields. New fields are generated when the user clicks on "+". This is developed using JavaScript.
It is easy to add an incremented value to an ID using JavaScript, but new rows are not made using the runat="server" so I am afraid my code behind won't see the values in the fields.
I want my code to loop through each form "row" and grab each item. Then take this data and insert it into a SQL database. How do I get that working?
I can give you some guides to continue from the point you are (and solve this question - so I am afraid my code behind won't see the values in the fields.)
a. You create your controls using java-script on the page.
b. User then is post them back, what you have all ready known, with some new controls that code behind didn't know about.
now the trick here is that you grab this return
HttpContext.Current.Request.Form
and analyse it to see whats "is new there", what are the new post controls that you don't know about - and then you create them on code behind again - and gets their input values.

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.

How to distinguish modified item in binding list?

I am developing a windows application using C# and .net 4.5 under visual studio 2013 IDE.
In my application when the user attempt to enter a new data the program creates an object of appropriate class let's call the class DataClass and the to be objectOfDataClass.
The objectOfDataClass is added to a BindingList<DataClass> let it be bindingListOfDataClass which is bounded to a DataGridView as a data viewer.
The user enters data in a text boxes then he/she press a button to add text boxes value as a list item to bindingListOfDataClass and then he/she can view all data records on the DataGridView.
Then the user has a choice to click save button to save the data to a file or database.
All of these functions are working very well without any problem. But I want to add another function to mark or distinguish the new data entry or the modified cells on the datagridview and the bindingList by changing the style format of that cell (i.e: changing the background color or font style ..etc) before the user click the save button so he/she is notified to confirm any changes before saving the new entries.
The comparison should be between the saved data (the data on the file or database) and the data shown in the datgridveiw.
Now I am looking for a best solution which must achieves higher performance and preserve memory. so any suggestion please?
Exactly here you need to distinguish newly added items and already saved items
from the list So you can easily use flag for this....
When you click on Add Button you can false your flag & then true..Before items saved you can change color or something else where flag false..

list view problem with respect to my problem

I have a listview in wpf and i am swapping two items index..
the swapping must be visible to the user.
i tried giving thread delay..
it didnt work
How to do that..
If I was going to do this I would delete the list view and lock it up where you can't use it again. Then code whatever your list view was outputting in C# using whatever you use to query your database(I think LINQ to SQL is the most robust solution right now) and then use a string builder to construct the html. This way you can assign a id to each div and append an incrementing number to the end of the id. Finally you could write your javascript and use the id's. Here is a link that shows how to build a gridview without using a gridview control.
See the first answer to the question in this link: How to show pop up menu from database in gridview on each gridview row items?
I am not sure whether it will work for your problem or not.
I think you need some kind of animation there. If it is web project, you can use jQuery animation to do that.

Categories

Resources