c# - 如何选择特定的下拉列表项目

标签 c# asp.net gridview

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/

相关文章:

asp.net - VB.net 1.1 - 有 Continue For 吗?

c# - 如何更改 PdfPTable 中的字体大小?

android - GridView 中的特定 TextView 未在应用程序初始化时更新

c# - 是否有可能总是消除 goto 的?

c# - Ninject - 使用单一接口(interface)的多个类(有多个匹配的绑定(bind)可用)

c# - 如何从 MongoDB 中的 ChangeStream 过滤对特定字段的更新

asp.net - 客户端身份验证 - 处理客户端证书

c# - 使用 asp.net 使用下一个、上一个按钮和显示总页数的分页 gridview

c# - 如何更改行 MouseOver 上的 GridView 单元格颜色

c# - 不能在 MongoDb C# 上将 Linq 与嵌套类 List<> 一起使用