我的下面是metod:
private void BindModels(int makeID, int typeID)
{
try
{
DataSet ds = (DataSet)ViewState["ds_DDLsData"];
EnumerableRowCollection models;
if (typeID != null)
{
models = from dt_Models in ds.Tables[10].AsEnumerable()
where 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 = from dt_Models in ds.Tables[10].AsEnumerable()
where 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());
}
}
我打来电话:
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());
}
}
问题是在某些情况下,类型下拉列表可以为空。我的问题是BindModels方法应该是什么样子,因为现在我收到错误 - 输入字符串的格式不正确。在此先感谢您的回复。