Click here to Skip to main content
Rate this: bad
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++) {
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";
    var id = "ctl00_ContentPlaceHolder1_gridColumn_ctl0" + j + "_ddlcolumnname";
    var dropdown1 = document.getElementById(id);
    var id2 = "ctl00_ContentPlaceHolder1_gridColumn_ctl0"+ j +"_ddlcolumndata";
    var dropdown2 = document.getElementById(id2);
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
Rate this: bad
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');

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

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

  Print Answers RSS
0 OriginalGriff 476
1 Sergey Alexandrovich Kryukov 215
2 CHill60 195
3 Afzaal Ahmad Zeeshan 145
4 TheRealSteveJudge 120
0 Sergey Alexandrovich Kryukov 9,061
1 OriginalGriff 7,920
2 Peter Leow 4,774
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,176

Advertise | Privacy | Mobile
Web04 | 2.8.150327.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