This topic is locked

combine form fields into single field for insert/update

9/23/2013 12:25:03 PM
ASPRunner.NET General questions
M
mgilbert65 author

Greetings! I have a SQL field char(7) which holds the days of the week a 'something' should run. Each position of the field corresponds to a day of the week. For example if this something should only run on Monday's, then the field contains '1000000' (1 meaning run, 0 meaning not run). In ASPRunner.Net I have a checkbox for each day of the week and I wrote my SQL query to split out each position and populate the checkboxes accordingly. To this point everything is smooth. However, when I need to insert or update a record, how do put the checkbox values back into a 7 char string? Do I need a custom command button and hide the normal save button (is this even possible)? What would the code look like to concatenate the checkbox values? Any insight you can give is appreciated greatly.

Sergey Kornilov admin 10/2/2013

Ok, here is a quick example. I assume that your char(7) field name is Week while checkboxes are named ch1, ch2, ch3 etc. You can use BeforeEdit event for this purpose and here is your code:

values["Week"]=64*values["ch7"]+32*values["ch6"]+16*values["ch5"]+8*values["ch4"]+4*2*values["ch3"]+2*values["ch2"]+values["ch1"];

values.Remove("ch1");

values.Remove("ch2");

values.Remove("ch3");

values.Remove("ch4");

values.Remove("ch5");

values.Remove("ch6");

values.Remove("ch7");
return true;