Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
342
After Deleting row, edit key column to reorder number.
posted

Hello,

I have a webdatagrid bound to a SQLDataSource.  Table looks like below

ControlNum           SubNum          MyDate

20100617.02              1                     06/25/2010

20100617.02              2                     06/30/2010

20100617.02              3                    07/14/2010

20100617.02              4                     06/08/2010

When I want to delete a row (for example row with SubNum=2),  I can delete fine and everything works great.  Now the number of rows left in the table is three (SubNums: 1, 3, and 4 are left) 

Right after I delete I would like to edit the rest of the SubNums so that the row where Subnum =3 is changed to =2.  and row where SubNum=4 is now =3.  The Grid then should look like this:

ControlNum           SubNum          MyDate

20100617.02              1                     06/25/2010

20100617.02              2                    07/14/2010

20100617.02              3                    06/08/2010

 

I would like to do this in Javascript.  I have come up with the below code but for some reason after I delete the row and try to change the Subnum it  will give me error "this._props is null or not an object"

script type="text/javascript"

 

 

var selectedDataKey = "";

 

 

var changed = false;

 

 

 

function onRowSelectionChanged(sender, eventArgs) {

 

 

var rows = eventArgs.getSelectedRows();

 

 

var selectedRow = rows.getItem(0);

selectedDataKey = selectedRow.get_dataKey();

}

 

 

function DeleteCorr() {

 

 

var answ = confirm("Are you sure you want to delete this correspondence?")

 

 

if (answ) {

 

if (selectedDataKey != "") {

 

 

var grid = $find("<%= wdgSubmission.ClientID %>");

 

 

var rows = grid.get_rows();

 

 

var row = rows.get_rowFromKey(selectedDataKey);

 

 

var subnum = row.get_cell(1).get_value();

 

 

var sub = subnum-=1

 

 

var rowl = rows.get_length();

rows.remove(row, false

);

 

 

 

if (subnum < rowl) {

 

 

for (var x = sub; x <= rowl - 1; ++x) {

 

 

var cgrid = $find("<%= wdgSubmission.ClientID %>");

 

 

var crows = cgrid.get_rows();

 

var crow = crows.get_row(x+1);

 

crow.get_cell(1).set_value(x+1);

 

}

 

 

 

}

 

}

 

 

else

{

alert("

Please select a row to remove.");

}

}

 

 

else {

}

 

</

 

script>

Thanks!

Kavita Patel