我想在按钮点击时将Dropdownlist值设置为默认(选择)。 [英] I want to set the Dropdownlist value to defaul(select) on button click.
本文介绍了我想在按钮点击时将Dropdownlist值设置为默认(选择)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我的应用程序中有一个下拉列表。
我想要的是每次点击重置按钮时它应该设置为默认值(选择)。
这是我的重置代码。
Hi i have a dropdownlist in my Application.
What i want is each time when i click on the Reset button it should set to default value(select).
Here is my code for reset.
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";
}
这是我的下拉列表代码:
Here is my dropdownlist code:
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();
}
任何人都可以帮助我实现这一目标。
Can any one please help me to achieve this.
推荐答案
试试这个:
Try this:
public void ResetControl()
{
DDLContainer.Items.Insert(00, "Select");
DDLCountryLoading.Items.Insert(00, "Select");
DDLCountryDestination.Items.Insert(00, "Select");
DDLContainer.SelectedIndex = 0;
DDLCountryLoading.SelectedIndex = 0;
DDLCountryDestination.SelectedIndex = 0;
ImageMode.ImageUrl = "~/ShowImageMode.ashx?Mode=A";
}
嗨
我刚刚调用了DDL函数。它可以像我想要的那样工作。
这是我的工作代码
Hi
I just Called the DDL functions.It works as what i want.
Here is my working code
public void ResetControl()
{
DDLContainer.Items.Clear();
DDLCountryLoading.Items.Clear();
DDLCountryDestination.Items.Clear();
mobjGenlib.PopulateCountry(DDLCountryDestination);
mobjGenlib.PopulateCountry(DDLCountryLoading);
mobjGenlib.PopulateContainerType(DDLContainer);
ImageMode.ImageUrl = "~/ShowImageMode.ashx?Mode=A";
}
感谢所有帮助过我的人。
Thanks for all Who helped me.
这篇关于我想在按钮点击时将Dropdownlist值设置为默认(选择)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文