在我的web應用程序中,當我選擇一個下拉控件,這是給錯誤的。 不能在DropDownList中選擇多個項目。這是我的代碼...在下拉控件selectedindexchanged事件中獲取錯誤?
try
{
ddlState.Items.Clear();
ddlState.Enabled = true;
ListItem li1 = new ListItem();
li1.Value = "0";
li1.Text = "Select State";
ddlState.Items.Add(li1);
clsStates.Countryid = int.Parse(ddlCountry.SelectedValue.ToString());
DataSet ds = clsStates.selectStateBl();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
li1 = new ListItem();
li1.Text = ds.Tables[0].Rows[i]["statename"].ToString();
li1.Value = ds.Tables[0].Rows[i]["stateid"].ToString();
ddlState.DataTextField = "statename";
ddlState.DataValueField = "stateid";
ddlState.Items.Add(li1);
}
}
catch
{
}
這是有約束力的國家代碼...
try
{
ListItem li = new ListItem();
DataSet ds = clsCountrys.selectCountryB();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
li = new ListItem();
li.Text = ds.Tables[0].Rows[i]["countryname"].ToString();
li.Value = ds.Tables[0].Rows[i]["countryid"].ToString();
if (li.Value == Session["usercountry"].ToString())
li.Selected = true;
ddlCountry.DataTextField = "countryname";
ddlCountry.DataValueField = "countryid";
ddlCountry.Items.Add(li);
}
}
catch
{
}
,這是國家結合到下拉控制..
try
{
ddlState.Items.Clear();
ddlState.Enabled = true;
ddlState.ClearSelection();
ListItem li1 = new ListItem();
li1.Value = "0";
li1.Text = "Select State";
ddlState.Items.Add(li1);
clsStates.Countryid = int.Parse(ddlCountry.SelectedValue.ToString());
DataSet ds = clsStates.selectStateBl();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
li1 = new ListItem();
li1.Text = ds.Tables[0].Rows[i]["statename"].ToString();
li1.Value = ds.Tables[0].Rows[i]["stateid"].ToString();
if (Session["userstate"].ToString() == li1.Value)
li1.Selected = true;
ddlState.DataTextField = "statename";
ddlState.DataValueField = "stateid";
ddlState.Items.Add(li1);
}
}
catch
{
}
檢查編輯答案會做工作,爲您 – 2010-09-02 09:10:47
檢查的代碼//代碼由pranay林蛙 – 2010-09-02 09:11:26
沒有pranay我的地方更新此塊代碼,但它給出了相同的錯誤 – 2010-09-02 09:52:19