473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Getting Data from a Table Control into a DataTable

gchq
96
Hi

Is there a way to get the data held in cells of a Table control into a DataTable? Since essentially (as I understand it) a DataTable is a Table element with <thead> and <tbody> elements there must be a method, but I haven't been able to find it yet!
Mar 23 '07 #1
4 1752
channaJ
67
Hi

Is there a way to get the data held in cells of a Table control into a DataTable? Since essentially (as I understand it) a DataTable is a Table element with <thead> and <tbody> elements there must be a method, but I haven't been able to find it yet!

Hi gchq,

By 'Table control' you are refering to a HTML table right..?

HTML table is rendered in the client side. If you want to add data to a DataTable, those data should be accessed from the server side. So it's not possible to do this.

Why don't you use a DataGrid server control here, which you can access from the server side.
Mar 23 '07 #2
gchq
96
Hi gchq,

By 'Table control' you are refering to a HTML table right..?

HTML table is rendered in the client side. If you want to add data to a DataTable, those data should be accessed from the server side. So it's not possible to do this.

Why don't you use a DataGrid server control here, which you can access from the server side.
By Table Control I meant a HTML Table that is now (by virtue of an id and runat=server) is also a .NET server control!
Mar 23 '07 #3
channaJ
67
By Table Control I meant a HTML Table that is now (by virtue of an id and runat=server) is also a .NET server control!
OK..then your table works as a server control. Now you can access it from the server side. Check the following code.

Expand|Select|Wrap|Line Numbers
  1.             DataTable dataTable = new DataTable();
  2.             dataTable.Columns.Add("td1");
  3.             dataTable.Columns.Add("td2");
  4.             foreach (HtmlTableRow row in tblTest.Rows)
  5.             {
  6.                 object[] values = new object[row.Cells.Count];
  7.                 for (int x = 0; x < row.Cells.Count; x++)
  8.                 {
  9.                     values[x] = row.Cells[x].InnerText;
  10.                 }
  11.                 dataTable.Rows.Add(values);
  12.             }
  13.  
Here tblTest is your HTML table. Hope this will make sence. Let me know if not.
Mar 23 '07 #4
gchq
96
OK..then your table works as a server control. Now you can access it from the server side. Check the following code.

Expand|Select|Wrap|Line Numbers
  1.             DataTable dataTable = new DataTable();
  2.             dataTable.Columns.Add("td1");
  3.             dataTable.Columns.Add("td2");
  4.             foreach (HtmlTableRow row in tblTest.Rows)
  5.             {
  6.                 object[] values = new object[row.Cells.Count];
  7.                 for (int x = 0; x < row.Cells.Count; x++)
  8.                 {
  9.                     values[x] = row.Cells[x].InnerText;
  10.                 }
  11.                 dataTable.Rows.Add(values);
  12.             }
  13.  
Here tblTest is your HTML table. Hope this will make sence. Let me know if not.
Thanks for the heads up on that - "HtmlTableRow" was the key I was looking for:_

Expand|Select|Wrap|Line Numbers
  1. Dim gTable As New DataTable()
  2.         Dim gRow As DataRow = Nothing
  3.         gTable.Columns.Add("Amount") 'GetType(Double))
  4.         gTable.Columns.Add("Item_Date") 'GetType(Date))
  5.         Dim row As HtmlTableRow
  6.         For Each row In Table1.rows
  7.             gRow = gTable.NewRow()
  8.             gRow("Amount") = row.Cells(0).InnerText
  9.             gRow("Item_Date") = row.Cells(1).InnerText
  10.             gTable.Rows.Add(gRow)
  11.         Next
  12.  
  13.         'test with gridview
  14.         GridView1.DataSource = gTable
  15.         GridView1.DataBind()
Works a treat! Thanks again!

Just got to to mess with coverting the types and I'm there :-)
Mar 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
3
by: renil | last post by:
I have a repeater control that displays info. from a datatable. Each row in the repeater has a checkbox. Also, I have a delete linkbutton outside the repeater control. What I'm trying to do when...
4
by: tshad | last post by:
I have a DataTable which has the headings in row 0. I do the following: PayDates.DataSource=mDt; PayDates.DataTextField= "Pay Date"; PayDates.DataValueField="Pay Date"; PayDates.DataBind();...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
1
by: Rich | last post by:
Hello, I am trying to use the Reportviewer control. I have been following an example from the web, and the instructions from the help files on set up a ..rdlc and binding it to the reportviewer...
3
by: h4xPace | last post by:
I am building a MySQL query application, and I have run into a small snag. MySQL has released a set of classes that extend the .NET framework base data classes (command, connection, etc), and I am...
2
by: Andrew Cooper | last post by:
Greetings, I've got a website that has several pages with DataGrid controls on them. The controls are bound to Object Datasources. On one of the pages I keep getting a "Timeout expired. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.