奇怪!DropDownList的问题! Me.DropDownList1.Items.RemoveAt(序号)序号是唯一的Me.DropDownList1.Items.Remove(某项的内容)某项的内容可能不是唯一的吧? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 某项的内容可是唯一的啊!就算不是唯一的,DropDownList1.Items.Remove(string)既然有这种属性,它应该移去所有内容为“某项的内容”的项啊。 可以删除.我的测试代码:<%@ Page language="C#" runat="server" debug=true%> <html> <head> <script language="C#" runat="Server"> void aa() { wz1.Items.Clear(); wz2.Items.Clear(); int k; int i; for (i=0;i<3;i++) { k=i+1; ListItem item1=new ListItem(); ListItem item2=new ListItem(); item1.Text="WZ00"+k; item1.Value="WZ00"+k; item2.Text="WZ00"+k; item2.Value="WZ00"+k; wz1.Items.Add(item1); wz2.Items.Add(item2); } } public void Page_Load(object sender, EventArgs e) { aa(); int i; for (i=0;i<2;i++) { if (i==0) { wz1.Items[wz1.SelectedIndex].Selected=false; wz1.Items[0].Selected=true; } if (i==1) { wz2.Items[wz2.SelectedIndex].Selected=false; wz2.Items[1].Selected=true; } } } void click(object obj, EventArgs e) { wz1.Items.RemoveAt(0); wz2.Items.Remove("WZ002"); } </script> </head> <body> <form runat="server"> <asp:DropDownList id=wz1 runat=server></asp:DropDownList> <asp:DropDownList id=wz2 runat=server></asp:DropDownList> <br> <asp:button id=bu Text="Remove" Onclick=click runat=server/> </form> </body> </html> 非动态绑定的DropDownList也可以.譬如:<%@ Import namespace="System.Drawing"%><%@ Page language="C#" debug="True"%><html> <head> <script language="C#" runat="server"> void Button_Click(Object sender,EventArgs e) { DropDownList1.Items.RemoveAt(1); } void remove(object obj, EventArgs e) { DropDownList2.Items.Remove("color2"); } </script> </head> <body> <form runat="server"> <h4><font face="verdana">DropDownList </h4></font> <asp:DropDownList id="DropDownList1" BorderColor="Lightgreen" runat="server"> <asp:ListItem>color1</asp:ListItem> <asp:ListItem>color2</asp:ListItem> <asp:ListItem>color3</asp:ListItem> <asp:ListItem>color4</asp:ListItem> </asp:DropDownList> <asp:DropDownList id="DropDownList2" BorderColor="Lightgreen" runat="server"> <asp:ListItem>color1</asp:ListItem> <asp:ListItem>color2</asp:ListItem> <asp:ListItem>color3</asp:ListItem> <asp:ListItem>color4</asp:ListItem> </asp:DropDownList> <br><br> <asp:Button id="Button1" Text="RemoveAt" OnClick="Button_Click" runat="server"/> <asp:Button id="bu" Text="Remove" OnClick="remove" runat="server"/> </form> </body></html> 也可以删除的啊 Me.DropDownList1.Items.Remove(某项的内容)你说的“某项的内容”是指什么?是ListItem的Value值还是Text值? DropDownList1.Items.Remove有两种重载形式:DropDownList1.Items.Remove(System.Web.UI.WebControls.ListItem Item);DropDownList1.Items.Remove(string Item);你看看事不是参数指定的不正确! to webdiyer(webdiyer) :是Text值 PlaceHolder取控件ID(求解) 怎么获取一个Button的坐标?即top和left! extjs3.0为何不能用啊 哪位能把这个函数改为asp.net下可以运行的函数,谢谢! 关于gridview显示记录数的问题!急~~~~~ 将文件放在数据据中,但是下载时怎么变成了乱码 急急急~~用VSS工具Chein的ASP.NET项目不能调试 在vs2003中怎么在table里加控件? 急,哪个好心人帮帮忙咯! ASP.NET时尚编程百例中的一个例子中的几句话弄不懂是为什么?高手请进!!! 客户端打印问题(急需) 大家看看这是什么错误
就算不是唯一的,DropDownList1.Items.Remove(string)既然有这种属性,它应该移去所有内容为“某项的内容”的项啊。
<%@ Page language="C#" runat="server" debug=true%>
<html>
<head>
<script language="C#" runat="Server">
void aa()
{
wz1.Items.Clear();
wz2.Items.Clear();
int k;
int i;
for (i=0;i<3;i++)
{
k=i+1;
ListItem item1=new ListItem();
ListItem item2=new ListItem();
item1.Text="WZ00"+k;
item1.Value="WZ00"+k; item2.Text="WZ00"+k;
item2.Value="WZ00"+k; wz1.Items.Add(item1);
wz2.Items.Add(item2);
}
} public void Page_Load(object sender, EventArgs e) {
aa();
int i;
for (i=0;i<2;i++)
{
if (i==0)
{
wz1.Items[wz1.SelectedIndex].Selected=false;
wz1.Items[0].Selected=true;
}
if (i==1)
{
wz2.Items[wz2.SelectedIndex].Selected=false;
wz2.Items[1].Selected=true;
}
}
}
void click(object obj, EventArgs e) {
wz1.Items.RemoveAt(0);
wz2.Items.Remove("WZ002");
}
</script>
</head>
<body>
<form runat="server">
<asp:DropDownList id=wz1 runat=server></asp:DropDownList>
<asp:DropDownList id=wz2 runat=server></asp:DropDownList>
<br>
<asp:button id=bu Text="Remove" Onclick=click runat=server/>
</form>
</body>
</html>
譬如:
<%@ Import namespace="System.Drawing"%>
<%@ Page language="C#" debug="True"%><html>
<head>
<script language="C#" runat="server">
void Button_Click(Object sender,EventArgs e)
{
DropDownList1.Items.RemoveAt(1);
}
void remove(object obj, EventArgs e) {
DropDownList2.Items.Remove("color2");
}
</script>
</head>
<body>
<form runat="server">
<h4><font face="verdana">DropDownList </h4></font>
<asp:DropDownList id="DropDownList1" BorderColor="Lightgreen" runat="server">
<asp:ListItem>color1</asp:ListItem>
<asp:ListItem>color2</asp:ListItem>
<asp:ListItem>color3</asp:ListItem>
<asp:ListItem>color4</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList id="DropDownList2" BorderColor="Lightgreen" runat="server">
<asp:ListItem>color1</asp:ListItem>
<asp:ListItem>color2</asp:ListItem>
<asp:ListItem>color3</asp:ListItem>
<asp:ListItem>color4</asp:ListItem>
</asp:DropDownList>
<br><br>
<asp:Button id="Button1" Text="RemoveAt" OnClick="Button_Click" runat="server"/>
<asp:Button id="bu" Text="Remove" OnClick="remove" runat="server"/> </form>
</body>
</html> 也可以删除的啊
你说的“某项的内容”是指什么?是ListItem的Value值还是Text值?
DropDownList1.Items.Remove(System.Web.UI.WebControls.ListItem Item);
DropDownList1.Items.Remove(string Item);
你看看事不是参数指定的不正确!