2014년 1월 7일 화요일

[Tip]DropDownList Control에 동적으로 데이터바인딩 하기[재직자무료교육/프로그래머교육/구로디지털IT교육,오라클/자바/닷넷/C#/iOS/안드로이드/아이폰교육]

[Tip]DropDownList Control에 동적으로 데이터바인딩 하기[재직자무료교육/프로그래머교육/구로디지털IT교육,오라클/자바/닷넷/C#/iOS/안드로이드/아이폰교육]


아래는 addrbook 이라는 테이블의 tel, name 컬럼중...

text에 name, value에 tel을 매핑 시키는 예 입니다.
(DataAdapter를 사용하지 않았습니다.)

private void Page_Load(object sender, System.EventArgs e)
{
string ConStr = ("server=(local);uid=sa;pwd=pass;database=pubs");
SqlConnection Conn = new SqlConnection(ConStr);                               
Conn.Open();
string sql = "select name, tel from addrbook ";       
       
SqlCommand myCommand = new SqlCommand(sql, Conn);

SqlDataReader myReader =  myCommand.ExecuteReader();

int i=0;
                       
DropDownList1.DataSource = myReader;
DropDownList1.DataValueField = "tel";
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();                       

}
 

  • JAVA
  • ORACLE
  • iPhone/Android
  • .NET
  • 표준웹/HTML5
  • 채용/취업무료교육
  • 초보자(재학생)코스

  • 댓글 없음:

    댓글 쓰기