473,799 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Data from a Table Control into a DataTable

gchq
96 New Member
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 1766
channaJ
67 New Member
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 New Member
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 New Member
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 New Member
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 - "HtmlTableR ow" 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
5261
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 structures? Thanks for any hints, Leszek Taratuta
1
2695
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, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I am missing something basic here... Need help... Thanks much
7
14821
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 want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
3
7842
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 the delete linkbutton is clicked is get the SubscriptionID from the repeater control for each row in which the checkbox is checked, then call a delete function. (See the code for the .aspx and .aspx.cs below.) The problem I'm having is that I...
4
3661
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(); PayDates.Items.Insert(0, "Select Date");
5
6455
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 dataset with a join query for the GetData() select method. I use ObjectDataStore to couple the GridView with the table adapter on the dataset. If I point the ODS at the child table, the GridView will bind to the "normal" select and I end up...
1
17958
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 control. The help files state that in the form the contains the reportviewer control there is a tasks smart tags panel in design view. I don't see any such thing. Where do I need to look to see this panel? So I have been trying to follow...
3
5994
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 using them to interact with the MySQL server (on localhost). Everything works great on that side of the aisle. However, I have never worked with getting schema from a database before, so I am fumbling around for a workable solution to doing...
2
2839
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 timeout period elapsed prior to completion of the operation or the server is not responding." error. The data is being filled from a Stored Procedure on an SQL Server. When I run the Stored Procedure on the actual server, it is only taking 24...
0
10473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.