2013-01-22 46 views
3

如何從HTML表格添加數據到數據庫中?如何在asp.net的html表格中插入數據到數據庫中

我的表是這樣的:

html += "<table>"; 
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + </th></tr>"; 
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + </td></tr>"; 
html += "</table>"; 

我打電話從服務器端的HTML。

+0

那你在「我打電話從服務器端的HTML。」是什麼意思?你是從服務器端創建這個html嗎?請提供更多詳細信息 –

+0

表示我在.cs頁面中編寫了上述代碼 – Optimus

回答

1

如果你喜歡純HTML,你可以使用像Knockout.js一樣的JavaScript框架。 Knockout.js允許您使用JavaScript View Models將數據注入HTML。按鈕點擊可以分配給視圖模型中的JavaScript功能。 JavaScript函數可以執行AJAX帖子來調用服務器端的控制器操作方法 - 這會將數據插入到數據庫中。

有關淘汰賽更多信息,請http://knockoutjs.com

0

使用System.Text.RegularExpressions(正則表達式)來搜索模式來替換表標籤:

更換<tr><th><tr><td>空白,

更換</th></tr></td></tr>^^~~~~~~~~~~^^指示端線。

取代</td><td>||^^^^^^^^^||表示定界符

string html = // your html table goes here 
string[] lines = html.Split(new string[] { "^^~~~~~~~~~~^^" }, StringSplitOptions.None); 
// now your html table is divided into lines, which means rows 

// lines[0] = // the header 
// lines[1] = // row 1 
// lines[2] = // row 2 
// lines[3] = // row 3 
// ... 
// ... 

// line 1 is the header/column name 
string[] columns = lines[0].Split(new string[] { "||^^^^^^^^^||" }, StringSplitOptions.None); 

// columns[0] = // 1st column name 
// columns[1] = // 2nd column name 
// columns[2] = // 3rd column name 
// ... 
// ... 

for (int i = 1; i < lines.Length; i++) 
{ 
    string[] data = lines[i].Split(new string[] { "||^^^^^^^^^||" }, StringSplitOptions.None); 
    // data[0] = // 1st data 
    // data[1] = // 2nd data 
    // data[2] = // 3rd data 
    // ... 
    // ... 
} 
相關問題