问题描述
使用的代码是这个.... plsss告诉我这个错误...
受保护的void DropDownList2_SelectedIndexChanged(对象发送者,EventArgs e)
{
int countryId = int.Parse(DropDownList1.SelectedIndex.ToString());
DataTable dt = new DataTable();
dt = bindDropDown(从tblcountry中选择countryid,countryname,其中tblcountry.regionid =" + countryId);
DropDownList1.DataSource = dt;
DropDownList1.DataValueField ="countryid";
DropDownList1.DataTextField =国家名称";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0,new ListItem(-Select--","0"));
}
公共DataTable bindDropDown(字符串查询)
{
SqlDataAdapter dataAdapter =新的SqlDataAdapter(query,con);
DataSet dataSet =新的DataSet();
dataAdapter.Fill(dataSet);
return(dataSet.Tables [0]);
}
在表单加载事件中
如果(!IsPostBack)
{
DataTable dt1 =新的DataTable();
dt1 = bindDropDown(从tblregion中选择tblregion.regionid,tblregion.regionfullname");
DropDownList2.DataSource = dt1;
DropDownList2.DataTextField ="regionfullname";
DropDownList2.DataValueField ="regionid";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0,new ListItem(-Select--","0"));
}
the code is used is this ....plsss tell me the error in this...
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
int countryId = int.Parse(DropDownList1.SelectedIndex.ToString ());
DataTable dt = new DataTable();
dt = bindDropDown("select countryid,countryname from tblcountry where tblcountry.regionid =" + countryId );
DropDownList1.DataSource = dt;
DropDownList1.DataValueField = "countryid";
DropDownList1.DataTextField = "countryname";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--Select--", "0"));
}
public DataTable bindDropDown(string query)
{
SqlDataAdapter dataAdapter = new SqlDataAdapter(query,con);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
return (dataSet.Tables[0]);
}
in the form load event
if (!IsPostBack)
{
DataTable dt1 = new DataTable();
dt1 = bindDropDown("select tblregion.regionid,tblregion.regionfullname from tblregion");
DropDownList2.DataSource = dt1;
DropDownList2.DataTextField = "regionfullname";
DropDownList2.DataValueField = "regionid";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("--Select--", "0"));
}
推荐答案
这篇关于如何根据另一个dropdownlist值填充dropdownbox值....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!