Click here to Skip to main content
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 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
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