I want to interate through the rows of the webgrid and find out if the id of the currentrow being added is already there in the grid meaning if that row with that id is alreadyexists how can this be done on the client side.
I solved it using above code as mentioned by McDonald. Thanks
Thanks for your reply. Here is what I am trying to do. I have a search button which when clicked pop up a modal pop up where the users search for some criteria once they click the get button on the modal pop up I am creating a new row on the webgrid which is on my page. What I want is when they again click on the same search which has the same criteria it should not create a new row. Basially no row should be same in my webgrid. I hope i made it clear. here is what I am using right now:
function PopulateIndividualGrid( Id,type,name)) { debugger; var grid = igtbl_getGridById('<%=grid.ClientID %>'); var gridRow; var activeRow = igtbl_getActiveRow('<%=grid.ClientID %>'); if(activeRow!=null) { gridRow = igtbl_addNew('<%=grid.ClientID %>',0); } else { igtbl_setActiveRow('<%=grid.ClientID %>',igtbl_getElementById('<%=grid.ClientID %>')); gridRow = igtbl_addNew('<%=grid.ClientID %>',0); } gridRow.getCell(0).setValue(id); gridRow.getCell(1).setValue(type); gridRow.getCell(2).setValue(name); ; }
So I have the ID which I am passing to this function. Now before adding a new row I want to iterate through my grid and see if this id already exists in some row. Please suggest. Thanks
In the below JavaScript solution, I'm making a number of assumptions:
var found = false;for (var i = 0; i < grid.Rows.length; i++){ var row = grid.Rows.getRow(i); var idCell = row.getCellFromKey("ID"); if (idCell.getValue() == newId) found = true;}