Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在.net网站中使用c重新读取呈现的HTML表_C#_.net - Fatal编程技术网

C# 在.net网站中使用c重新读取呈现的HTML表

C# 在.net网站中使用c重新读取呈现的HTML表,c#,.net,C#,.net,在页面加载事件上呈现html表。然后我想在点击按钮时提交表格,并读取每个单元格的内容。下面是我为创建表而创建的代码 <html> <script runat="server" > void Page_Load(Object sender, EventArgs e) { // Create the HtmlTable control. HtmlTable table = new HtmlTable

在页面加载事件上呈现html表。然后我想在点击按钮时提交表格,并读取每个单元格的内容。下面是我为创建表而创建的代码

    <html>
   <script runat="server" >

      void Page_Load(Object sender, EventArgs e)
      {

         // Create the HtmlTable control.
         HtmlTable table = new HtmlTable();
         table.Border = 1;
         table.CellPadding = 3;
         table.ID = "testTable";


         // Populate the HtmlTable control.

         // Create the rows of the table.
         for(int rowcount=0; rowcount<5; rowcount++)
         {
            HtmlTableRow row = new HtmlTableRow();

            // Create the cells of a row. 
            for(int cellcount=0; cellcount<4; cellcount++)
            {
               HtmlTableCell cell;

               // Create table header cells for first row.
               if(rowcount <= 0)
               {
                  cell = new HtmlTableCell("th");
               }
               else
               {
                  cell = new HtmlTableCell();
               }

               // Create the text for the cell.
               cell.Controls.Add(new LiteralControl(
                   "row " + rowcount.ToString() + ", " + 
                   "column " + cellcount.ToString()));

               // Add the cell to the Cells collection of a row. 
               row.Cells.Add(cell);

            }

            // Add the row to the Rows collection of the table.
            table.Rows.Add(row);

         }

         // Add the control to the Controls collection of the 
         // PlaceHolder control.
         Place.Controls.Clear();
         Place.Controls.Add(table);

      }

   </script>

<body>

   <form id="Form1" runat="server">

      <h3> HtmlTable Example </h3> 

      <asp:PlaceHolder id="Place" runat="server"/>
   <asp:Button runat="server" Text="click me!" OnClick="Unnamed_Click" />
   </form>

</body>
</html>
这是非常简单的东西,但是我不知道在捕获按钮单击事件后如何开始从html表读取数据。 如果你们能提供任何帮助,我将不胜感激。我试着看这篇文章,但它们没有意义

注意:一旦我呈现了表,用户就可以在页面上使用javscript对其进行操作。因此,数据绑定在这里似乎不可行,但我可能错了。
我也看到了很多关于html agility pack的提及,尽管看起来好像我所做的是没有必要的。

你最好的选择是让操纵表的javascript将操纵保持在页面上的隐藏字段中:

<input type="hidden" runat="server" id="tableData" />
然后想出一种格式化表数据的方法,类似于:row1:value,value,value\u row2:value,value,value。然后使用相同的javascript操作页面,使隐藏字段保持最新。如果无法更改操纵页面的javascript,可以将javascript添加到表中的每个单元格/行,以查找更改并更新隐藏值

退房:


这看起来与您需要的非常接近。

也许您应该将javascript添加到标记列表中,因为遍历表的DOM并将其转换为可以返回到服务器并具有某种意义的东西需要非常沉重的负担。我之前就已经这样做了,我希望有人会说我可以像使用更新面板一样使用它并读取表的内容。我想知道,除了制作jason数组并将其发回外,他们是否也是一种方法。如果您的用户打算通过JS处理此问题,也许您应该返回JSON而不是HTML表。如果您在表的每个单元格中添加say元素,则重新提交会更自动,但这会影响它的外观。即使在部分提交或更新面板中,表本身也没有要提交的内容。注意:有一些控件,如Repeater GridView等,支持到用户的往返-school@ebyrob即使我在表上使用runat server属性,我也无法从表中读取单元格的内容?