C# 动态设置asp:下拉列表的selectedIndex
我有一个文本将显示为选中,如“已选择”,“未选择” 动态地,我想设置“selected”如下 如何设置?请引导你就快到了C# 动态设置asp:下拉列表的selectedIndex,c#,C#,我有一个文本将显示为选中,如“已选择”,“未选择” 动态地,我想设置“selected”如下 如何设置?请引导你就快到了 dropdown.Items.FindByText("selected").Selected = true; 编辑 要通过javascript实现这一点,您必须循环使用下拉列表中的选项元素。像这样的 function setIndexByText() { drp = document.myform.selectcontrol; //this would be you
dropdown.Items.FindByText("selected").Selected = true;
编辑
要通过javascript实现这一点,您必须循环使用下拉列表中的选项元素。像这样的
function setIndexByText()
{
drp = document.myform.selectcontrol; //this would be your dropdown
str = "selected";
for (indx=0; indx < drp.options.length; indx++)
{
if (drp.options[indx].text == str)
{
drp.selectedIndex = indx;
}
}
}
函数setIndexByText()
{
drp=document.myform.selectcontrol;//这将是您的下拉列表
str=“选定”;
对于(indx=0;indx
我能用javascript完成吗?我能用javascript完成吗?
function setIndexByText()
{
drp = document.myform.selectcontrol; //this would be your dropdown
str = "selected";
for (indx=0; indx < drp.options.length; indx++)
{
if (drp.options[indx].text == str)
{
drp.selectedIndex = indx;
}
}
}