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 3:20am
Edited 2-Jan-13 3: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 CHill60 360
1 Sarvesh Kumar Gupta 248
2 OriginalGriff 218
3 Sergey Alexandrovich Kryukov 158
4 RyanDev 120


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