473,405 Members | 2,154 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,405 software developers and data experts.

remove other DataRows from your DataTable

remove other DataRows from your DataTable

Hi, I want to display the top three rows of the table.
So I just want to remove the other rows.
Suppose the datas are not from a database.
How to do it?

Thanks
Feb 13 '08 #1
3 1358
nateraaaa
663 Expert 512MB
remove other DataRows from your DataTable

Hi, I want to display the top three rows of the table.
So I just want to remove the other rows.
Suppose the datas are not from a database.
How to do it?

Thanks
You could use a for loop and make the boundary 3 so that it will only loop through the 1st 3 rows of your DataTable and return the data for the 1st 3 rows.

Nathan
Feb 13 '08 #2
I need more details because I tried to deleted the extra lines but the deleted parts are still displayed. Why? Thanks for your help.



Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.         {
  3.             DataTable t1 = new DataTable();
  4.             t1 = GetTable();
  5.             for (int i = 3; i < t1.Rows.Count; i++)
  6.                 t1.Rows.RemoveAt(i);
  7.             DataView dv = new DataView(t1);
  8.             dv.Sort = "Temperature ASC";
  9.             GridView1.DataSource = dv;
  10.             GridView1.DataBind();
  11.         }
  12.  
  13.         public DataTable GetTable()
  14.         {
  15.             DataSet newSet = new DataSet();
  16.             DataTable Index = new DataTable("Index");
  17.             GenerateDataSet(newSet,Index);
  18.             return Index;
  19.         }
.
Feb 26 '08 #3
nateraaaa
663 Expert 512MB
I need more details because I tried to deleted the extra lines but the deleted parts are still displayed. Why? Thanks for your help.



Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2. {
  3. DataTable t1 = new DataTable();
  4. t1 = GetTable();
  5. for (int i = 3; i < t1.Rows.Count; i++)
  6. t1.Rows.RemoveAt(i);
  7. DataView dv = new DataView(t1);
  8. dv.Sort = "Temperature ASC";
  9. GridView1.DataSource = dv;
  10. GridView1.DataBind();
  11. }
  12.  
  13. public DataTable GetTable()
  14. {
  15. DataSet newSet = new DataSet();
  16. DataTable Index = new DataTable("Index");
  17. GenerateDataSet(newSet,Index);
  18. return Index;
  19. }
.
If you only want the 1st 3 records you need your for loop set up like this
Expand|Select|Wrap|Line Numbers
  1.  for(int i = 0; i < 3; i++) 
  2. {
  3. //add each row to your datatable or dataview here
  4. }
  5.  
Nathan
Feb 26 '08 #4

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

Similar topics

1
by: frank | last post by:
I have two DataTables, A and B. Both have the primary key "CID". How do I remove all entries in Table A from Table B (with the same PK)?
3
by: Prince | last post by:
hi all, I need to insert a datarows collection from a datatable into a datagrid?can anyone tell me how to do??? Thanx in advance..
1
by: psb | last post by:
I thought this was weird?? is this a bug in framework 1.0??? (1.0 is the version I am running against) --------------------------- dim dtAll as new datatable dim dtTmp as datatable dtTmp =...
5
by: Nathan Sokalski | last post by:
I am writing an ASP.NET application in which I need to copy DataRows from one DataTable to another. When I use code such as the following: temprows = nodes.Select("state='PA'")...
9
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1....
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
3
by: creator_bob | last post by:
How do I create an array of datarows from a sorted list? I put a bunch of datarows into a sorted list to sort them. Then I got an array of the sorted elements. However, I cannot typecast them. ...
9
by: Nathan Sokalski | last post by:
I have a DataTable from which I only need a certain range of the DataRows. What I would like to do is copy a range of rows from one DataTable to a new DataTable like the following: For i As...
8
by: jehugaleahsa | last post by:
Hello: We wrote an entire application where we add our DataRows to our DataTables immediately. However, we have to shut off our constraints to do this. We would like to use detached DataRows to...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.