是否可以在asp SelectedValue c#中使用SelectedText找到一个.net?
发布于 2022-10-25 11:03:47
为什么不直接使用DropDownList的SelectedValue属性?
好吧,如果您有一个字符串,并且想要Value的DropDownList的ListItem (它将这个字符串作为Text ),您可以使用LINQ:
string value = ddl.Items.Cast<ListItem>()
.FirstOrDefault(item => item.Text == text)?.Value;https://stackoverflow.com/questions/74193009
复制相似问题