我是新來的編程和目前工作的一個C#asp.net網站從數據庫ON_LOAD填充Telerik的RadComboBoxes。輸入字符串的不正確的格式C#ASP.NET
我有了15+組合框,當我從這些組合框選擇值的那些組合框選擇,必須使用在我的數據庫,通過一個真正的大表進行搜索的形式。一個gridView將顯示返回的數據。
我已經使用相同的代碼格式在我的項目的其餘部分,它完美的作品,但是當我從我的「位置」 DropDownBox選擇項目通過我的數據庫來搜索我的錯誤'Input string was not in a correct format'
和我找不出爲什麼
這裏是我的Location.cs類
區域屬性
[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; }
區法
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;
}
這裏是我用我的.aspx文件
RadTreeView trvLocation = (RadTreeView)cboLocation.Controls[2].FindControl("trvLocation");
if (trvLocation.SelectedValue != "")
{
var locationID = Convert.ToInt32(trvLocation.SelectedValue); //Error
predicates.Add(p => p.LocationID == locationID);
}
在//錯誤行的代碼是在哪裏我得到了「輸入字符串的不正確的格式」的錯誤,有什麼建議請。我無法理解爲什麼我有這個問題
預先感謝您
該錯誤表示您嘗試從中解析整數的字符串實際上並不包含有效整數。使用Int.TryParse – Satpal
放置一個斷點,看看你在'trvLocation.SelectedValue'中得到了什麼' – Habib
你看過'trvLocation.SelectedValue'返回什麼?什麼類型和/或價值? –