개발 이야기/Visual C#

DropDownList 데이터 바인딩 역정렬

사나에 2008. 8. 8. 11:26

 ds = OUTPUT.DataSet.Copy();

            string strValue = string.Empty;
            string strText = string.Empty;

            SortedList sl = new SortedList();

            int iTBRowsCount = ds.Tables[0].Rows.Count;

            for (int i = 0; i < iTBRowsCount; i++)
            {
                strValue = ds.Tables[0].Rows[i]["YEAR"].ToString() + ds.Tables[0].Rows[i]["MONTH"].ToString().PadLeft(2, '0');
                strText = string.Format("- {0}년 {1}월호 -", ds.Tables[0].Rows[i]["YEAR"].ToString(), ds.Tables[0].Rows[i]["MONTH"].ToString().PadLeft(2, '0'));

                sl.Add(strValue.ToString(), strText.ToString());
            }

            for (int i = 0; i < iTBRowsCount; i++)
            {
                AKLDrop_Month.Items.Insert(i, new ListItem(sl.GetByIndex(iTBRowsCount - i - 1).ToString(), sl.GetKey(iTBRowsCount - i - 1).ToString()));
            }

            // 선택한 값을 설정해준다.
            AKLDrop_Month.SelectedValue = sYear + sMonth;