2014-03-05 40 views
2

ddlCountry採用以上技術已經結合如何選擇具體的下拉列表項目

ddlCountry.DataValueField= "CountryId" 
ddlCountry.DataTextFiled= "CountryName"; 
ddlCountry.DataSource= objCountry.Select(); 
ddlCountry.DataBind(); 

現在在gridview selectedIndex改變的事件我想設置下拉的值。我怎樣才能做到這一點?? 背後的GridView選擇指數的變化我這樣做代碼

ddlCountry.SelectedItem.Text = gvCountry.SelectRow.Cells[1].text; 

但是這使得項目的重複 所以我需要做哪些DDL屬性將選擇我需要的文本???

回答

0

它應該工作

ddlCountry.Items.FindByText(gvCountry.SelectRow.Cells[1].text).selected = true; 
2

你可以做如下

string gridText = gvCountry.SelectRow.Cells[1].text; 

if (ddlCountry.Items.FindByText(gridText) != null) 
{ 
    ddlCountry.ClearSelection(); 
    ddlCountry.Items.FindByText(gridText).Selected = true; 
} 
相關問題