我想保存从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”; –