본문 바로가기
개발언어/ASP.NET

Difference between DropDownList.Items.Add and DropDownList.Items.Insert method

by 엔돌슨 2009. 6. 12.
반응형

http://www.dotnetfunda.com/interview/exam223-difference-between-dropdownlistitemsadd-and-dropdownlistitemsinser.aspx


드랍다운리스트에 추가하기

            drd_CustType.Items.Clear();
            drd_CustType.Items.Insert(0, new ListItem("거래처유형0", "0"));
            drd_CustType.Items.Insert(1, new ListItem("거래처유형1", "1"));
            drd_CustType.Items.Insert(2, new ListItem("거래처유형2", "2"));
            drd_CustType.Items.Insert(3, new ListItem("거래처유형3", "3"));

이렇게 해야 value값이 있다.



DropDownList.Items.Add method allows you to add new ListItem into the DropDownList. This item will be added as the last item of the DropDownList.

dropDownList.Items.Add(new ListItem("Default Panel", "0"));


DropDownList.Items.Insert method allows you to specify the index of the item within the DropDownList where you want to insert the ListItem.

dropDownList.Items.Insert(0, new ListItem("Default Panel", "0"));


Here Default Value will be added as the first item in the DropDown.