在 page_load 中,我创建一个表并用从数据库收集的数据填充它。然后在允许用户修改它之后,我需要对数据库进行更改。但我不知道该怎么做。我环顾四周,现在比开始时更加困惑。我创建表的代码如下所示: delList.Controls.Clear();
Table tbl = new Table();
tbl.ID = "tbl1";
tbl.BorderWidth = 1;
delList.Controls.Add(tbl);
此代码被添加到占位符中:
<asp:PlaceHolder ID="delList" runat="server"></asp:PlaceHolder>
我想在页面底部有一个按钮,允许用户选择以保存更改,但我不知道如何执行此操作。主要是因为会有很多行需要更新。我在想使用 javascript 解析表可能是最简单的,然后以某种方式调用一个函数来一次更新数据库一行。但我不确定这是否可能。
我们将不胜感激所有帮助。
最佳答案
如果您使用专门针对此类操作的控件,则会容易得多。我的意思是像 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.
关于c# - 将用户生成的内容添加到 asp.net 中的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6220517/