handling Radio buttons in Formview with ObjectDataSource

G

Guest

What is the best way to handle data interpolation between form controls and
the actual sql data field. I have radio buttons that need to be interpreted,
form values that have to be translated.. e.g.

if (tbDaysDriveAlone.Text > 0) sb.Append( @"drive\");
if (tbDaysVanPool.Text > 0) sb.Append(@"vanPool\");
if (tbDaysCarpool > 0) sb.Append(@"Carpool\");
myObjectInstance.CommuteMethod = sb.ToString();

Should this be done in an event method generated by the update command or in
the update method of the business object... not sure how to proceed when
using ObjectDataSource.

Thanks for any advice.
 
G

Guest

Your question is a bit ambiguous. What exactly is the method named
"myObjectInstance.CommuteMethod" doing? You are passing it a string that you
composed from the values entered on some controls but then what does that
string do?
 
G

Guest

Sorry ;) CommuteMethod is actually method of commuting, not a function. It is
a property in a data object object RegistrantDetails which can be inserted
into my database with update method in business object RegistrantDB.
<asp:ObjectDataSource ID="odsRegistrant" runat="server"
TypeName="RegistrantDB" DataObjectTypeName="RegistrantDetails"
UpdateMethod="UpdateRegistrant" >

Thanks.
 
G

Guest

Ok, that removes one part of the mystery; the other part is the “Radio
buttons†(which appears as the subject of this thread) relationship to the
posted code (which seems to be attempting to compose a string from textbox
values but has no radio buttons in it).

Are you asking “how to databind a property to the values of 3 or more
controls (including radio buttons)?â€

If it turns out to be the case, then I would split that one field (named
CommuteMethod) into 3 different public properties (tbDaysDriveAlone,
tbDaysVanPool, tbDaysCarpool ) that are bound separately to each control.
Then during the update method I would concatenate the three into the
parameter that you need to pass through to the actual query.

This would allow you to expose a bool property that can be bound easily to
the radiobuttonlist but then you would translate it to a string when you
concatenate the 3 properties.
 
G

Guest

Ok I think you're saying, have a public property in the dataobject class for
each element in the form instead of just having properties for the sql data
elements I'm trying to store. Is that right?

(The radio buttons were just a second example, the stringbuilder example was
a bunch of checkboxes. I like the way you produced a combed solution ;)

I wouldn't have thought along these lines, I would more likely have
retreated back to the old style dataset coding with manual mapping of
textboxes to dataset fields (ughhh with 50+ fields). Thanks for the tip!!
 
G

Guest

Dabbler said:
Ok I think you're saying, have a public property in the dataobject class for
each element in the form instead of just having properties for the sql data
elements I'm trying to store. Is that right?

Yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top