This is a migrated thread and some comments may be shown as answers.

Input string was not in the correct format C# ASP.NET

2 Answers 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Goat_
Top achievements
Rank 1
Goat_ asked on 16 Apr 2013, 12:55 PM
I'm currently working on a C# asp.net website that populates Telerik RadComboBoxes with a treeView from a database on_load.

I have a form that has 15+ ComboBoxes and when I select values from those ComboBoxes those ComboBox selections must be used as filter to search through a large table in my database. A gridView will display the returned data.

I have used the same format of code throughout the rest of my project and it works perfectly, But when I select an item from my "Location" DropDownBox and select a CHILD node to search through my database I get the error 'Input string was not in a correct format' and I'm guessing its because i am using null values

here is my Location.cs Class

region Properties
 
    [Key]
    public int LocationID { get; se; }
    [Column("Location")]
    public string LocationName { get; set; }
    private int? _ParentLocationID;
    [Column]
    public int? ParentLocationID
    {
        get
        {
            return _ParentLocationID;
        }
        set
        {
            if (value == 0)
            {
                _ParentLocationID = null;
            }
            else
            {
                _ParentLocationID = value;
            }
        }
    }
 
    [Column]
    public int SiteID { get; set; }
    [Column]
    public bool Active { get; set; }
 
region Method
 
    public static IEnumerable<Location> LoadActiveLocations(int siteID)
    {
        iThNkContext db = new iThNkContext();
 
        var LocationList = (from l in db.Locations
                                where(l.SiteID == siteID && l.Active == true)
                                orderby l.LocationID
                                select l).ToList();
 
        return LocationList;
    }

And here is the code I am using in my .aspx file

RadTreeView trvLocation = (RadTreeView)cboLocation.Controls[2].FindControl("trvLocation");
         if (trvLocation.SelectedValue != "")
         {
            var locationID = Convert.ToInt32(trvLocation.SelectedValue);  //Error
            predicates.Add(p => p.LocationID == locationID);
        }

On the //Error line is where I am getting the 'Input string was not in the correct format' error, any suggestions please. I cant understand why I am having this problem or how to get values from child nodes.

thank you in advance


2 Answers, 1 is accepted

Sort by
0
MasterChiefMasterChef
Top achievements
Rank 2
answered on 16 Apr 2013, 03:53 PM
Hi Goat_,

Just wanted to point out, I don't know if this will fix your issues, but you are missing a character on your Key definition:
region Properties
  
    //[Key]
    //public int LocationID { get; se; }
 
    [Key]
    public int LocationID { get; set; }

Master Chief
0
Goat_
Top achievements
Rank 1
answered on 22 Apr 2013, 12:35 PM
sorry that was just a copy and paste problem, i must have deleted a character once i was done pasting
Tags
Grid
Asked by
Goat_
Top achievements
Rank 1
Answers by
MasterChiefMasterChef
Top achievements
Rank 2
Goat_
Top achievements
Rank 1
Share this question
or