您好我的应用程序中有一个下拉列表。 我想要的是每次当我点击重置按钮时它应该设置为默认值(选择)。
这是我的重置代码。
public void ResetControl()
{
DDLContainer.SelectedIndex = 0;
DDLCountryLoading.SelectedIndex = 0;
DDLCountryDestination.SelectedIndex = 0;
//DDLContainer.Items.Insert(0, new ListItem(" --SELECT--", "0"));
ImageMode.ImageUrl = "~/ShowImageMode.ashx?Mode=A";
}
这是我的下拉列表代码:
void ddlCountry()
{
con.Open();
cmd = new SqlCommand("select Distinct(mCRY_VCName) from TB_TransCountry", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DDLCountryLoading.DataSource = ds;
DDLCountryLoading.DataSourceID = String.Empty;
DDLCountryLoading.DataTextField = "mCRY_VCName";
DDLCountryLoading.DataValueField = "mCRY_VCName";
DDLCountryLoading.DataBind();
DDLCountryLoading.Items.Insert(0, new ListItem(" --SELECT--", "0"));
DDLCountryDestination.DataSource = ds;
DDLCountryDestination.DataSourceID = String.Empty;
DDLCountryDestination.DataTextField = "mCRY_VCName";
DDLCountryDestination.DataValueField = "mCRY_VCName";
DDLCountryDestination.DataBind();
DDLCountryDestination.Items.Insert(0, new ListItem(" --SELECT--", "0"));
con.Close();
}
void ddlContainer()
{
con.Open();
cmd = new SqlCommand("select Distinct(mCNT_VCTypeName) from TB_TransContainerType", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DDLContainer.DataSource = ds;
DDLContainer.DataSourceID = String.Empty;
DDLContainer.DataTextField = "mCNT_VCTypeName";
DDLContainer.DataValueField = "mCNT_VCTypeName";
DDLContainer.DataBind();
DDLContainer.Items.Insert(0, new ListItem(" --SELECT--", "0"));
con.Close();
}
任何人都可以帮助我实现这一目标。
答案 0 :(得分:0)
试试这个 DDLContainer.Items [0] .Selected = true;
答案 1 :(得分:0)
你有重置方法所以你可以通过设置从-1开始的SelectedIndex来设置索引,或者你可以使用属性selectedValue并设置值。