user3432257 user3432257 - 1 year ago 98
ASP.NET (C#) Question how to remove all the rows from a table except the first one

In the past i was using this


To remove all the rows.

Now I want to remove all the rows except the first one.

why I want that?

because when I remove all the rows, the
is removed, i don't want that. i want to remove all the data. not the

this is what i don't want to remove


what I have tried

I make this loop:

for (int i = 0; i < DateBookingTable.Rows.Count; i++) {
if (i >0){
//here what should I do

but I didn't know how to remove that row in the looop

Answer Source

In your loop you can use


You can modify your loop to start with 1 instead of 0 and thus avoiding checking it against 0 in each iteration.

for (int i = 1; i < DateBookingTable.Rows.Count; i++)

if you want to remove rows from client side using jQuery then you can do:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download