티스토리 뷰
public class Address
{
public string RegionID { get; set; }
public string RegionName { get; set; }
}
DropDownList 생성
<%: Html.DropDownList("name", new[] { new SelectListItem{ Text="text", Value="value"} }, "초기 출력 값") %>
DropDownList DB연동
public List<Address> SiList()
{
SqlConnection conn = new SqlConnection(this.connectionString);
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandType = System.Data.CommandType.StoredProcedure;
comm.CommandText = "Address_Select_Si";
SqlDataReader reader = comm.ExecuteReader();
List<Address> items = new List<Address>();
while(reader.Read())
{
items.Add(new Address{ RegionID = reader["do"].ToString(), RegionName = reader["do"].ToString() });
}
reader.Close();
conn.Close();
return items;
}
<%: Html.DropDownList("si", (SelectList)ViewData["address_si"], new { @onchange = "siInitial();" })%>
3개의 DropDownList 컨트롤 하기
Control(앞에 선택한 값을 기준으로 뒤에 있는 항목들의 최상위 항목을 자동으로 보여주기 위한 것이다.)
[HttpGet]
public PartialViewResult CurrentWeather()
{
string initialSi = "서울특별시";
string initialGu = "송파구";
string initialDong = "가락본동";
this.address = new AddressInheritance(new AddressImplement(this.connectionString));
ViewData["address_si"] = new SelectList(this.address.SiList(), "RegionID", "RegionName", initialSi);
ViewData["address_gu"] = new SelectList(this.address.GuList(initialSi), "RegionID", "RegionName", initialGu);
ViewData["address_dong"] = new SelectList(this.address.DongList(initialSi, initialGu), "RegionID", "RegionName", initialDong);
CurrentWeather currentWeather = GetCurrentWeather(this.x, this.y);
return PartialView("CurrentWeather", currentWeather);
}
[HttpPost]
public PartialViewResult CurrentWeather(string si, string gu, string dong)
{
CurrentWeather currentWeather = null;
this.address = new AddressInheritance(new AddressImplement(this.connectionString));
SelectList siSelectList = new SelectList(this.address.SiList(), "RegionID", "RegionName", si);
ViewData["address_si"] = siSelectList;
ArrayList guArrayList = null;
SelectList guSelectList = new SelectList(this.address.GuList(si), "RegionID", "RegionName", gu);
ViewData["address_gu"] = guSelectList;
SelectList dongSelectList = null;
if (guSelectList.SelectedValue != null)
{
dongSelectList = new SelectList(this.address.DongList(si, guSelectList.SelectedValue.ToString()), "RegionID", "RegionName", dong);
}
else
{
guArrayList = new ArrayList();
foreach(Address item in guSelectList.Items)
{
guArrayList.Add(item.RegionID);
}
dongSelectList = new SelectList(this.address.DongList(si, guArrayList[0].ToString()), "RegionID", "RegionName", dong);
}
ViewData["address_dong"] = dongSelectList;
if (guSelectList.SelectedValue == null || dongSelectList.SelectedValue == null)
{
ArrayList dongArrayList = new ArrayList();
foreach (Address item in dongSelectList.Items)
{
dongArrayList.Add(item.RegionID);
}
string guInitial = guSelectList.SelectedValue == null ? guArrayList[0].ToString() : guSelectList.SelectedValue.ToString();
Coordinate xy = this.address.Getxy(siSelectList.SelectedValue.ToString(), guInitial, dongArrayList[0].ToString());
currentWeather = GetCurrentWeather(xy.X, xy.Y);
}
if (siSelectList.SelectedValue != null && guSelectList.SelectedValue != null && dongSelectList.SelectedValue != null)
{
Coordinate xy = this.address.Getxy(siSelectList.SelectedValue.ToString(), guSelectList.SelectedValue.ToString(), dongSelectList.SelectedValue.ToString());
currentWeather = GetCurrentWeather(xy.X, xy.Y);
}
return PartialView("CurrentWeather", currentWeather);
}
View
<form id="addressForm" action="<%: Url.Action("CurrentWeather") %>" method="post">
<%: Html.DropDownList("si", (SelectList)ViewData["address_si"], new { @onchange = "siInitial();" })%>
<%: Html.DropDownList("gu", (SelectList)ViewData["address_gu"],new { @onchange = "guInitial();" })%>
<%: Html.DropDownList("dong", (SelectList)ViewData["address_dong"], new { @onchange = "document.getElementById('addressForm').submit();" })%>
</form>
- Total
- Today
- Yesterday
- 인텔리제이(intellij)
- REST API
- 특정 문자를 기준으로 자르기
- java.sql
- .submit()
- java 키워드 정리
- java-개발 환경 설정하기
- 표현 언어(expression language)
- System.Diagnostics
- docker
- jstl(java standard tag library)
- 문자 자르기
- nl2br
- React
- jstl(java standard tag library)-core
- 스프링 시큐리티(spring security)-http basic 인증
- 람다식(lambda expression)
- 스프링 프레임워크(spring framework)
- error-java
- 진수 변환
- await
- 스프링 프레임워크(spring framewordk)
- jsp 오픈 소스
- In App Purchase
- 스프링 시큐리티(spring security)
- MainActor
- 제품 등록
- java web-mvc
- system.io
- 메이븐(maven)
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |