Question repeater control

SQLKing

New member
Joined
Apr 19, 2013
Messages
4
Programming Experience
10+
I am trying to convert a VB web application to a C# web application mostly because the VB version that I inherited is a mess. Unfortunately, my C# skills have fallen behind since I haven't built anything myself in about 8 years.
The issue I'm having is that there is a repeater control that populates from a recordset. Then later on the page they set the value of the an object using the selected item in repeater control:
thisTeam.ModelCode = rcModel.SelectedValue

ModelCode is defined by an enumeration. Now in VB I'm guessing this worked somehow as VB is not very concerned with types when it compiles but in C# I get errors that the object is undefined or I can't set the object = to the repeater control etc.
 
The fact that the VB version was a mess was a good reason to clean it up but, assuming that it is VB.NET, it probably would have made more sense just to improve the VB version in situ rather than start again from scratch.

Anyway, I would guess that the model codes are stored in the database as integers so, if the SelectedValue returns an 'int' in your C# app then you simply cast that as your enumerated type. Enumerations are just numbers under the hood and 'int' values by default so you can simply cast back and forth between the two types as required, assuming that the 'int' values are valid. Obviously a .NET enumerated value cannot be stored in a database so they are usually stored as integers.
 
thanks for the post. It did turn out that the enumeration was causing the problem. Seems that VB converts enum to int with no problem but C# is more type-sensitive. So I had to change the function calls to accept int instead of the enumeration type and it seems to be working now.
BTW: I'm converting the whole thing from VB to C# mostly because I get paid by the hour and also because I want to get more C# experience on my resume.
 
So I had to change the function calls to accept int instead of the enumeration type and it seems to be working now.
No you didn't. What you should have done was left the method parameter as it was and cast the 'int' as that enumerated type, as i said in my previous post.
BTW: I'm converting the whole thing from VB to C# mostly because I get paid by the hour and also because I want to get more C# experience on my resume.
I guess we won't tell your client that you're ripping them off then.
 
No you didn't. What you should have done was left the method parameter as it was and cast the 'int' as that enumerated type, as i said in my previous post.I guess we won't tell your client that you're ripping them off then.

No this was the first thing I tried. thisTeam.ModelCode=(int)(rcModel.SelectedValue) - produces an error also tried the Int32.Parse function which also produces an error. The problem was that thisTeam.ModelCode expected a value of type Model. If you can explain how I can cast rcModel.SelectedValue to the enumeration type Model which is a custom type I'll try it but casting to an int does not work when the function is expecting the enumeration type of Model. So what you are saying is that your post did not help me at all and I actually resolved this on my own.
 
Back
Top Bottom