0
국가 드롭 다운 목록에서 값을 선택하면 다른 모든 드롭 다운 목록 상자의 값이 재설정되고 선택한 국가도 재설정됩니다.드롭 다운 목록에서 값을 선택할 때 다른 모든 드롭 다운 값이 재설정됩니다.
국가 드롭 다운 목록, 상태 드롭 다운 목록 및 지구 드롭 다운 목록은 종속적입니다.
private void BindDropDownList(DropDownList ddl, string query, string text, string value, string defaultText)
{
string conString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
con.Open();
ddl.DataSource = cmd.ExecuteReader();
ddl.DataTextField = text;
ddl.DataValueField = value;
ddl.DataBind();
con.Close();
}
}
ddl.Items.Insert(0, new ListItem(defaultText, "0"));
}
protected void gCountry2_SelectedIndexChanged(object sender, EventArgs e)
{
gState2.Enabled = false;
gDistrict2.Enabled = false;
gState2.Items.Clear();
gDistrict2.Items.Clear();
//gState2.Items.Insert(0, new ListItem("Select State", "0"));
//gDistrict2.Items.Insert(0, new ListItem("Select City", "0"));
int countryId = int.Parse(gCountry2.SelectedItem.Value);
if (countryId > 0)
{
string query = string.Format("select StateId, StateName from States where CountryId = {0}", countryId);
BindDropDownList(gState2, query, "StateName", "StateId", "Select State");
gState2.Enabled = true;
Page.SetFocus(f2.ClientID);
}
}
protected void gState2_SelectedIndexChanged1(object sender, EventArgs e)
{
gDistrict2.Enabled = false;
gDistrict2.Items.Clear();
//gDistrict2.Items.Insert(0, new ListItem("Select City", "0"));
int stateId = int.Parse(gState2.SelectedItem.Value);
if (stateId > 0)
{
string query = string.Format("select CityId, CityName from Cities where StateId = {0}", stateId);
BindDropDownList(gDistrict2, query, "CityName", "CityId", "Select City");
gDistrict2.Enabled = true;
Page.SetFocus(f2.ClientID);
}
"선택한 국가도 재설정됩니다."- 국가 드롭 다운을 바인딩하는 방법을 표시하십시오. –
감사합니다 알렉스 이것은 내가 페이지로드에 사용하는 코드입니다. ----------------------- if (! IsPostBack) { string query = "Select CountryId , CountryName 국가 이름 "; BindDropDownList (gCountry2, query, "CountryName", "CountryId", "Select Country"); gState2.Enabled = false; gDistrict2.Enabled = false; gState2.Items.Insert (0, 새 ListItem ("Select State", "0")); gDistrict2.Items.Insert (0, 새 ListItem ("Select City", "0")); \t} –