c# - Drop down list - input string was not in correct format -
i have below metod:
private void bindmodels(int makeid, int typeid) { try { dataset ds = (dataset)viewstate["ds_ddlsdata"]; enumerablerowcollection models; if (typeid != null) { models = dt_models in ds.tables[10].asenumerable() dt_models.field<int>("makeid") == makeid & dt_models.field<int>("typeid") == typeid select new { modelname = dt_models.field<string>("modelname"), modelid = dt_models.field<int>("modelid") }; } else { models = dt_models in ds.tables[10].asenumerable() dt_models.field<int>("makeid") == makeid select new { modelname = dt_models.field<string>("modelname"), modelid = dt_models.field<int>("modelid") }; } ddlmodel.datasource = models; ddlmodel.datatextfield = "modelname"; ddlmodel.datavaluefield = "modelid"; ddlmodel.databind(); ddlmodel.items.insert(0, new listitem("-- select model --", "-1")); ddlmodel.selectedindex = 0; } catch (exception ex) { var error = new javascriptserializer().serialize(ex.message.tostring()); scriptmanager.registerstartupscript(this, this.gettype(), "myalert", "alert('" + error + "');", true); methods.logerrors(session["user"].tostring(), this.page.tostring(), methodbase.getcurrentmethod().name.tostring(), ex.tostring()); } }
which call from:
protected void ddlmake_selectedindexchanged(object sender, eventargs e) { try { if (pnlmodels.visible == false) { pnlmodels.visible = true; } bindmodels(convert.toint32(ddlmake.selectedvalue), convert.toint32(ddltype.selectedvalue)); } catch (exception ex) { var error = new javascriptserializer().serialize(ex.message.tostring()); scriptmanager.registerstartupscript(this, this.gettype(), "myalert", "alert('" + error + "');", true); methods.logerrors(session["user"].tostring(), this.page.tostring(), methodbase.getcurrentmethod().name.tostring(), ex.tostring()); } }
the problem in cases type drop down list can empty. question how bindmodels method should like, because receiving error - input string not in correct format. in advance reply.
Comments
Post a Comment