Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net how to remove all the rows from a table except the first one

Tags:

c#

asp.net

In the past i was using this

DateBookingTable.Rows.Clear();

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 th is removed, i don't want that. i want to remove all the data. not the th

this is what i don't want to remove

<tr><th>ID</th><th>PlanTime</th></tr>

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

like image 498
user3432257 Avatar asked Oct 12 '25 07:10

user3432257


1 Answers

while (MyTable.Rows.Count > 1) MyTable.Rows.RemoveAt(1);
like image 96
user3158212 Avatar answered Oct 13 '25 21:10

user3158212