I am trying to save the changes I make when I select a different value from the DropDownList. But I am getting this error
Value cannot be null. Parameter name: String [ArgumentNullException: Value cannot be null. Parameter name: String]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10722118 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +145 System.Int32.Parse(String s) +23
I think the problem is its not finding the ID of the value in the DropDownList so it catches on this line in the update statement 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);
}
}
How do I get the ID of the value I select from the DropDownList?
Here's the code to populate the 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"));
}
}
I know this ddlTrailerLoc.DataValueField = "Description";
should be set to TrailerID or something but it will only work when it is Description. Changing this makes the DropDownList display the wrong values
Just guessing with the information you've provided, but should this line:
actually be:
Otherwise not sure from that code where TrailerID is set.