我想保存從DropDownList中選擇不同值時所做的更改。但我得到這個錯誤如何從DropDownList獲取ID?
值不能爲空。參數名稱:String [ArgumentNullException: 值不能爲空。參數名:字符串]
System.Number.StringToNumber(字符串str的NumberStyles選項, NumberBuffer &數的NumberFormatInfo信息,布爾parseDecimal) 10722118 System.Number.ParseInt32(字符串s的NumberStyles風格的NumberFormatInfo信息)+145 System.Int32.Parse(String s)將+23
我認爲問題是它沒有找到值的ID在DropDownList所以抓住這條線的更新語句Trailer.UpdateTrailer(int.Parse(TrailerID),
protected void ddlTrailerLoc_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlTrailerLoc=sender as DropDownList;
if (ddlTrailerLoc != null)
{
ddlTrailerLoc.SelectedValue.ToString();
Trailer.UpdateTrailer(int.Parse(TrailerID), Company.Current.CompanyID,txtTrailerReg.Text,ddlTrailerLocation.Text);
}
}
我該如何? et我從DropDownList中選擇的值的ID?
下面的代碼來填充的DropDownList
protected void PopulateDDLs(DropDownList ddlTrailerLoc)
{
DataSet dsTrailerLocation = DataUtils.GetAllGenSmall(Company.Current.CompanyID, "Description", "", 1, false, "Description", false, "TrailerLocationNOCODE", 0);
if (dsTrailerLocation.Tables[0].Rows.Count > 0)
{
ddlTrailerLoc.DataSource = dsTrailerLocation;
ddlTrailerLoc.DataValueField = "Description";
ddlTrailerLoc.DataTextField = "Description";
ddlTrailerLoc.DataBind();
}
else
{
ddlTrailerLoc.Items.Insert(0, new ListItem("No Locations Entered", "0"));
}
}
我知道這ddlTrailerLoc.DataValueField = "Description";
應設置爲TrailerID或東西但是當它被描述它只會工作。改變這使得DropDownList中顯示錯誤的值
從您的示例中不清楚TrailerID變量的初始化位置。 您可能需要在事件處理程序中顯式初始化它,如下所示:TrailerID =((Trailer)ddlTrailerLoc.SelectedValue).TrailerID,其中Trailer是DropDownList項目的類 –
將DropDownList Value和Text Field設置爲遵循ddlTrailerLoc。 DataValueField =「Trailer_ID」; //你想要的ID字段 ddlTrailerLoc.DataTextField =「Trailer_Name」; –