Click here to Skip to main content
11,492,523 members (66,362 online)
Rate this: bad
good
Please Sign up or sign in to 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...

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:

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 2-Jan-13 4:20am
Edited 2-Jan-13 4:22am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 454
1 Maciej Los 266
2 KarstenK 210
3 CPallini 208
4 Sascha Lefèvre 190
0 Sergey Alexandrovich Kryukov 10,062
1 OriginalGriff 8,620
2 Sascha Lefèvre 3,609
3 Maciej Los 3,372
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100