dropdownlist动态添加item
如何在dropdownlist动态添加item之后,如何设置其value值! /用JS控制服务端dropDownlist和textField的Readonly属性
一共有两种写法:《不使用的数据源的方式》
1):
ListItem myListItem = new ListItem("text","value");
this.DropDownList1.Items.Add(myListItem);
2):
this.DropDownList1.Items.Add("text1");
this.DropDownList1.Items.FindByText("text1").Value = "value1";
3):用JS控制服务端dropDownlist和textField的Readonly属性
<asp:DropDownList ID="ddlCardType" runat="server"></asp:DropDownList>
Readonly = disabled
document.getElementById("<%=ddlCardType.ClientID %>").disabled="disabled";
document.getElementById("<%=txtLastFour.ClientID %>").disabled="disabled";
如何根据DropDownList的Items的text值得到它的index值?
_____________________________________________________________________________________________
答1:
這個好想要遍歷DropDownList
int drpidex(DropDownList drp,string str){
for(int i=0;i<drp.Item.Count;i++)
if (drp.SelectedItem.Text==str)
return i;
}
本文介绍了在ASP.NET中如何动态地为DropdownList添加项并设置其值的方法,包括使用ListItem对象直接设置值及通过JavaScript控制服务器端DropdownList和TextField的只读属性。此外,还提供了根据DropdownList项的文本获取其索引的代码示例。

2533

被折叠的 条评论
为什么被折叠?



