Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
hi i am using a grid view in a page and i want to delete the contents of the gridview means the rows which are not needed using javascript i can clear the entire contents of gridview and also the all 'td' of gridview using a single jquery like gridviewid.clear(); line but i do not want to clear all contents i want to keep the 2 rows then after 2 rows what ever extra rows are there in gridview i want to delete using javascript or jquery i tried like this...

C#
for(var j =2 ;j<=rowscount;j++) {
    grd.deleteRow(3);}


but i am not able to get this right its not working i had also tried to take each contents by using following code:

C#
for(var j =2 ;j<=rowscount;j++) {
var lblid = "ctl00_ContentPlaceHolder1_gridColumn_ctl0"+ j +"_Label2";
    $(document.getElementById(lblid)).empty();
    var id = "ctl00_ContentPlaceHolder1_gridColumn_ctl0" + j + "_ddlcolumnname";
    var dropdown1 = document.getElementById(id);
    $(dropdown1).empty();
    var id2 = "ctl00_ContentPlaceHolder1_gridColumn_ctl0"+ j +"_ddlcolumndata";
    var dropdown2 = document.getElementById(id2);
    $(dropdown2).empty();
}


but the empty() function is clearing all contents in page full page becomes empty and to delete the rows based on row number i do not have anything as row number in gridview means i have 2 dropdowns and a textbox within the gridview so how to i clear all the datas after 2 rows please can u help me the coding in javascript or jquery...

thanking you in advance!
Posted
Updated 2-Jan-13 3:22am
v2

i tried it using the javascript like this

                var grd1 = document.getElementById('ctl00_ContentPlaceHolder1_gridColumn');
grd1.deleteRow(k);


where k is the row which u want to delete i got row by using grd1.rows.length
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900