且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在vb的下拉列表中删除选定的值?

更新时间:2022-10-18 14:02:16

使用这个
项目的属性默认选择为
,另一个属性为AppendDataBoundItems = true







 

>< asp:DropDownList ID =DropDownList1runat =serverAppendDataBoundItems =true>

< asp:ListItem Text =VolvoValue =1Selected =True>< / asp:ListItem>

< asp:ListItem Text = MarutiValue =2>< / asp:ListItem>

< asp:ListItem Text =SwiftValue =3>< / asp:ListItem>

< / asp:DropDownList>


如果我理解正确,这就是你想要的:

下拉值为1, 2,3,4,5

你选择4.

现在再次单击下拉列表的向下箭头,它显示4作为选定值。

现在发生的事情:显示值1 ,2,3, 4,5列表

你想做什么:在列表中显示值1,2,3,5。从列表中删除4,只因为它已被选中。



我的解决方案:

你想做的不是标准行为下拉控制。更不用说,它只会让用户感到困惑。

你不能这样做,因为如果从列表中删除它,就无法选择它。


在ASP下拉中,据我所知,它无法完成。我在html中找到了解决方法。看看这对你有帮助。当我将格式从下拉列表更改为列表并列表下拉到这两个按钮单击时,可能是您可以在单击时执行此操作。对不起,由于我的时间不多,无法发布更好的示例。 

< 选择 id = T >
< 选项 value = volvo > Volvo < / option >
< 选项 value = saab > Saab < / option >
< 选项 = mercedes > Mercedes < / option >
< 选项 value = audi > 奥迪< / option >
< / select >
< input type = 按钮 önclick = T.multiple ='multiple'; value = b1 / >
< 输入 type = button önclick = T.multiple =''; value = b2 / >


写下你的下拉填充代码是回发条件因为我在下面的例子中调用了fillDropdown函数。



 如果  IsPostBack 然后 
FillDropdown()
结束 如果


Hai
In my web application,i will bind data in dropdownlist and make one values as selected value from list,selected value appear in drop down box,if i click down arrow from drop down, selected value appear in list also(i.e)2 times appear in drop down one in drop box and another one in list ,my need is how to remove that value from list,bcz selected value show in top.

Is it possible,pls reply if not possible also.like cant do....
pls reply asap

Regards
AravindB

EDIT
-----------------
thank u for ur reply.i will use drop down list ,i will bind data in dropdown and i selecte one value from dropdownlist,after select at top selecet value appear and also in the list also value appear,my need is after selecte value ,only show on top and remove form list in same dropdown list box

use this 
There is a property for item that will be by default selected
and another property AppendDataBoundItems=true





"><asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" >
<asp:ListItem Text ="Volvo" Value ="1" Selected ="True" ></asp:ListItem>
<asp:ListItem Text ="Maruti" Value ="2"></asp:ListItem>
<asp:ListItem Text ="Swift" Value ="3"></asp:ListItem>
</asp:DropDownList>


If I understand correctly, this is what you want:
A drop down has values 1, 2, 3, 4, 5
First time, you click on down arrow of the drop-down, it shows all values in the list.
You select 4.
Now again you click on down arrow of the drop-down, it shows 4 as the selected value.
What happens now: shows value 1, 2, 3, 4, 5 in list
What you want to do:show values 1, 2, 3, 5 in list. Get rid of 4 from the list, just because it's selected.

My solution:
What you want to do is not the standard behaviour of drop down control. Not to mention, it will just confuse the users.
You can not do it, because if you remove it from the list, it can not be selected.

In ASP drop down, as far as I know, it can not be done. I found a work-around in html drop down. See if that helps you. As I change the format from drop-down to list and list to drop-down in these two button clicks, may be you can do that on click. Sorry, can not post better example as I'm running out of time.

<select id="T">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
    <input type="button"  önclick="T.multiple = 'multiple';" value="b1" />
    <input type="button"  önclick="T.multiple = '';" value="b2" />


write your dropdown fill code in is post back condition As i call fillDropdown function in example below .

If Not IsPostBack Then
   FillDropdown()
       End If