Solved

Public property of class has incorrect value

Posted on 2009-05-05
4
176 Views
Last Modified: 2013-12-17
Greetings all,

I have a DropDownList (ddlPortfolio_CI),  inside a FormView, that receives it's SelectedValue from another field (C_Portfolio) of the FormView. The dropDown also has a ListItem, added in source, to cater for null values (it;s value is set as ""  which is how a null value from the DB translates, and text as "-- None --",) read from the database.

The update method has as it's pararmeter an object which represents the fields of the FormView (saves tryping each field as a parameter).

When I update  with valid selection (ie sleecting anything other than "-- None --") then the update works fine. If I leave an entry as "-- None --" then I get an " is not a valid value for Int32" message[note: it is complainign about the "" value set for the added listitem] when updating - failure occurs in the public property, "C_Portfolio" of the parameter object.

Any thpoughts on what I should be doing?


In advance, thanks

    allanmark
SOURCE:
 
        <asp:FormView  ID="fvSpousal" runat="server" DefaultMode="ReadOnly" OnDataBound="fvSpousal_DataBound" DataSourceID="spousalODS"
                EnableViewState="true" DataKeyNames="C_Id,SP1_Id,SP2_Id" CssClass="smallFontSize" OnModeChanging="fvSpousal_ModeChanging" 
                OnItemCommand="fvSpousal_ItemCommand" OnItemUpdating="FvSpousal_ItemUpdating" >  
 ................
..................
...................
 <asp:DropDownList  ID="ddlPortfolio_CI" runat="server" DataSourceID="portfolioODS" DataTextField="PF_Title" DataValueField="PF_Id"
                       SelectedValue=<%# Eval("C_Portfolio") %> AppendDataBoundItems="true" Enabled="false">
                    <asp:ListItem Text="--- None ---" Value="" />
                    </asp:DropDownList>                    
........................
.....................
............................
        </asp:FormView>                       
 
        <asp:ObjectDataSource ID="spousalODS" runat="Server" SelectMethod="GetCouple" TypeName="BusinessLogic.Business" 
    OnSelected="spousalODS_Selected" OnSelecting="spousalODS_Selecting" UpdateMethod="SpousalODS_Update" 
     OldValuesParameterFormatString="{0}" DataObjectTypeName="DataTransferObjects.SpouseODS_DO"  OnUpdated="SpousalODS_Updated"   >
            <SelectParameters >
               <asp:QueryStringParameter Name="CoupleId"   DbType="Int32" Direction="Input"  />
            </SelectParameters>           
         </asp:ObjectDataSource>  
                         
 
CODE BEHIND (THE UPDATE M<ETHOD):
 
public static bool SpousalODS_Update(SpouseODS_DO spousal)
        {
            bool updateStatus;
 
            updateStatus = DataAccess.ApplyUpdateSpousal(spousal);
            
            return updateStatus;
        }
 
CODE BEHIND (THE CLASS FOR THE PARAMS OBJECT):
 
using System;
using System.Collections.Generic;
using System.Text;
 
namespace DataTransferObjects
{
    public class SpouseODS_DO
    {
        private int c_Id;
        private string c_Surname;
        private int? c_Portfolio;
	......................
	...................
	.................
 
        public SpouseODS_DO()
        {
 
        }
 
        public int C_Id
        {
            get { return c_Id; }
            set { c_Id = value; }
        }
 
        public string C_Surname
        {
            get { return c_Surname; }
            set { c_Surname = value; }
        }
 
        public int? C_Portfolio
        {
 
            get { return c_Portfolio; }
            set { c_Portfolio = value; }       
 
            }
        }
 
	...............
	...........
 
    }
}

Open in new window

0
Comment
Question by:allanmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:tculler
ID: 24308248
Remember that anything other than a number is unparseable. You need to change "" to null if you're storing it in a nullable int, and certainly from "-- None --" to null, as well. An empty string is not parseable.
0
 

Author Comment

by:allanmark
ID: 24308675
Tried changing "" to null, in the source -- how does one do that?
0
 
LVL 9

Accepted Solution

by:
tculler earned 250 total points
ID: 24309376
Just set whatever field you're trying to change to null " = null;"
For example, if I have a TextBox named txtExample, and I want the text to be "null", I would do the following:
txtExample.Text = null;

Open in new window

0
 

Author Closing Comment

by:allanmark
ID: 31578179
Many thanks!
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question