Add user generated content to a database in asp.net
In page_load, I create a table and fill it with data gathered from a database. Then after allowing the user to modify it, I need to make the changes to the database. But I'm not sure how to do this. I have been looking around and now am more confused then when I started. My code to create the table looks like this: delList.Controls.Clear();
Table tbl = new Table();
tbl.ID = "tbl1";
tbl.BorderWidth = 1;
de开发者_运维技巧lList.Controls.Add(tbl);
This code gets added to a placeholder:
<asp:PlaceHolder ID="delList" runat="server"></asp:PlaceHolder>
I want to have a button at the bottom of the page to allow the user to select in order to save the changes but I can't figure out how to do this. Mostly because there will be a lot of rows that need to be updated. I was thinking it might be easiest to parse through the table using javascript and then somehow calling a function to make update the database one row at a time. But I'm not sure if this is even possible.
All help will be greatly appreciated.
It would be a lot easier if you used a control that is specific to this kind of operation. I mean a control like GridView.
GridView displays the values of a data source in a table where each column represents a field and each row represents a record. The GridView control enables you to select, sort, and edit these items.
The GridView control is used to display the values of a data source in a table. Each column represents a field, while each row represents a record. The GridView control supports the following features:
- Binding to data source controls, such as SqlDataSource.
- Built-in sort capabilities.
- Built-in update and delete capabilities.
- Built-in paging capabilities.
- Built-in row selection capabilities.
- Programmatic access to the GridView object model to dynamically set properties, handle events, and so on.
- Multiple key fields.
- Multiple data fields for the hyperlink columns.
- Customizable appearance through themes and styles.
i dont get how the User Can modify content in a Table, unless you have some form Controls like Textbox, Dropdown list?
You should be creating form fields dynamically, and adding it to a container/form on the Page along with a button (which could do a postback/ or handle JavaScript).
You Could iterate through all controls in a parent container or add custom attributes to your form elements, do that you can identify those fields in JS/Clientside.
精彩评论