Hi,
I have a WebDataGrid attached to a SQLDataSource.
fields: (CompositeKey: ControlNum; ControlNumSub)
ControlNum (Hidden)
ControlNumSub(ReadOnly)
DueDate
RecievedDate
CompletedCode
I want the user to be able to add a new row on the gird by entering the DueDate, RecievedDate and CompletedCode. Once the user has entered the data they hit the <Enter> key. Before the row is commited I would like to enter the ControlNum and ControlNumSub values in the gird through Javascript. The ControlNum comes from a label that is on the same page. The ControlNumSub field needs to be calculated in that I will have to extract the previous row's ControlNumSub value and add 1 to it. (ex. Previous row ControlNumSub = 2; New Row value should = 3).
How would set the value of ControlNum and ControlNumSub before the user commits the row?
Been trying to figure this out for weeks!! :( please help!
Kavita Patel
You can handle the row adding client event and set the values there.
function rowAdding(grid, args) { var cellVals = args.get_cellValues(); for (var x = 0; x < cellVals.length; ++x) { if (cellVals[x].DataKeyField == "ControlNum") args.get_cellValues()[x].Value = yourVal; } }
Let us know if you need more help.
regards,
David Young
Hi David,
Thank you so much for your reply. This worked perfectly for the ControlNum but I still have an issue with the 2nd key 'ControNumSub' . Below is what I tried below but when i run it I get a [KeyNotFoundException]. I am thinking it has something to do with my grid having a composite key: DataKeyField = ControlNum, ControlNumSub.
Maybe instead of getting the "DataKeyField" in the for loop I can just get the Fieldname? If so how would I do that? If not, any other suggestions on how I can set value of both fields?
function onRowAdding(grid, args) {
var ControlNum = document.getElementById('<%=fvDetails.FindControl("ocd_control_numberLabel").ClientID %>').value;
var subnum = grid.get_rows().get_length() - 1;
var cellVals = args.get_cellValues();
for (var x = 0; x < cellVals.length; ++x) {
if (cellVals[x].DataKeyField == "ocd_control_num") {
args.get_cellValues()[x].Value = ControlNum;
}
else if (cellVals[x].DataKeyField == "ocd_submission") {
args.get_cellValues()[x].Value = subnum;
Thanks,
nevermind this works. my subnum is suppose to be +1 not -1; Works great thanks!