[英]I want to set default value that is missing when click on the dropdown list.I would like to be unable to select “Please select” value
[英]I want to set the Dropdownlist value to default value(eg : select) on each time the reset button click
嗨,我的應用程序中有一個下拉列表。 我想要的是每次我單擊“重置”按鈕時,它都應設置為默認值(選擇)。
這是我的重置代碼。
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();
}
誰能幫助我實現這一目標。
試試這個DDLContainer.Items [0] .Selected = true;
您具有重置方法,因此可以通過設置從-1開始的SelectedIndex來設置索引,或者可以使用屬性selectedValue並設置值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.