2014-06-17 3 views
1

asp.net C# 프로젝트에서 작업 중입니다. GridView 값/데이터를 TextBoxDropdownList으로 가져 와서 업데이트를 수행하고 싶습니다. TextBox에서 작동하는 것으로 보이지만 DropdownList은 작동하지 않는 것 같습니다. 제발 도와주세요.gridview 값을 드롭 다운리스트로 가져 오는 방법

txtempcode.Text = GridView1.SelectedRow.Cells[1].Text.Replace(" ", ""); 
dropdownlistgend.Text = GridView1.SelectedRow.Cells[2].Text.ToString(); 

답변

2

당신은 아마 대신 Text 속성을 변경의 드롭 다운리스트에 ListItem를 추가해야합니다.

string gridValue = GridView1.SelectedRow.Cells[2].Text.ToString(); 
DropDownList1.Items.Insert(0, new ListItem(gridValue, gridValue)); 
+0

나는 코드를 시도했지만 여전히 저를 위해 일하지 않습니다. 코드가 어떻게 작동하는지 설명해 주시겠습니까? – user3216802

+0

이것은 목록 항목을 드롭 다운에 추가합니다. 코드를 디버그 할 수 있습니까? – Adil

0

시도해보십시오. 도움이 될 수 있습니다.

DropDownList1.Items.Insert(0, new ListItem(GridView1.SelectedRow.Cells[2].Text.ToString(), GridView1.SelectedRow.Cells[2].Text.ToString())); 
관련 문제