ddlCountry
已绑定(bind)
ddlCountry.DataValueField= "CountryId"
ddlCountry.DataTextFiled= "CountryName";
ddlCountry.DataSource= objCountry.Select();
ddlCountry.DataBind();
使用上述技术。
现在在 gridview selectedIndex 更改事件上我想设置下拉列表的值。我怎样才能做到这一点?? 在 gridview 选择索引更改后面我正在执行此代码
ddlCountry.SelectedItem.Text = gvCountry.SelectRow.Cells[1].text;
但这会复制该项目 那么我需要做什么 ddl 属性将选择我想要的文本???
最佳答案
您可以执行以下操作
string gridText = gvCountry.SelectRow.Cells[1].text;
if (ddlCountry.Items.FindByText(gridText) != null)
{
ddlCountry.ClearSelection();
ddlCountry.Items.FindByText(gridText).Selected = true;
}
关于c# - 如何选择特定的下拉列表项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22190948/