从Access,我能够将表(访问表)发布到html表。从数据库到dataTable,再到html表,包括每行html表的dyanmic单选按钮。
选择单选按钮并按下编辑按钮时,应编辑所选行。做这个的最好方式是什么?我应该将选定的htmlRow放到数据表中,然后将数据表发布到列表中吗?
下面是我的代码
HtmlTableRow htmlrow=new HtmlTableRow();
htmlrow.Cells.Add(new HtmlTableCell() {InnerText = ""}); // creates an empty cell on row0, column0
//copy headings from datatable
foreach (DataColumn column in datatable.Columns)
{
htmlrow.Cells.Add(new HtmlTableCell() {InnerText = column.ColumnName});
}
//add new row
table1.Rows.Add(htmlrow);
//place values in html table from datatable
foreach (DataRow row in datatable.Rows)
{
htmlrow = new HtmlTableRow();
table1.Rows.Add(htmlrow);
RadioButton rad = new RadioButton();
rad.GroupName = "name"
rad.Attributes.Add("value", row[0].ToString());
//create first cell in a row with radioButton
HtmlTableCell cell = new HtmlTableCell()
htmlrow.Cells.Add(cell);
cell.Controls.Add(rad)
//add cell to the current row with the values from the datatable
for each (DataColumn column in datatable.Columns)
{
htmlrow.Cells.Add(new HtmlTableCell() {InnerText= row[column].ToString()});
}
}
//the current output is a table, with radioButton on its first column.
//the radioButton can only select one, which already works
//i already have an existing EditButton
//code below to be able to edit the html table named table1
编辑html表并将编辑过的部分保存回数据库的最佳方法是什么? 当按下EditButton时,是否应该将选定的rowSelected复制到list / gridview / etc以便用户可以编辑? 在用户编辑并按下保存之后,将列表/ gridview / etc中的数据复制到htmlTable是否明智。然后从html表,我复制回dataTable所以我可以将数据保存到数据库?