关于如何附加asp.net下拉列表的任何想法? [英] Any ideas on how to append an asp.net drop down list?

查看:63
本文介绍了关于如何附加asp.net下拉列表的任何想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试将数据绑定项附加到我的下拉列表中。附加部分似乎可以找到,但是当附加下拉列表时,新项目会被添加到列表中,但那里的旧项目似乎仍然留在列表中。



我有2个下拉列表,一个用于数据库名称,它将一个变量传递给sql中的存储过程,这样它就会返回一个数据列表来填充需要追加的下拉列表。



所以例如。如果我从下面的列表1中选择项目A,那么下拉列表2应该只为下拉列表1中的项目A填充项目。目前它只是不断添加数据而不是特定于第一个下拉列表。



谢谢。

Hi There,

I am trying to append databound items to my drop down list. The appending part seems to work find, however when the drop down list is being appended new items do get added to the list but the older items that were there are still seem to be staying in the list.

I have 2 drop down lists, one for database name which passes a variable to a stored procedure in sql so that it brings back a list of data to populate the drop down list that needs to be appended.

So for eg. if i select item A from down list 1 then drop down list 2 should be populated with items only for item A from drop down list one. At the moment it just keeps adding data instead of it being specific to the first drop down list.

thanks.

推荐答案

您可能在绑定后添加项目。

您可以使用
You are probably adding items after it is bound.
You can use
DropDownList1.Items.Clear();

to在添加任何项目之前,请从下拉列表中删除所有项目。



向我们展示您的代码,我们将能够提供更好的帮助。

to remove all items from the drop down list before you add any.

Show us your code and we will be able to help better.


在附加之前简单地从下拉列表中清除所有项目。

1. Dropdownlist1.item.clear();



比添加新项目:

2. Dropdownlist1.item.add(item_name);
simply Clear all the item from dropdownlist before appending.
1. Dropdownlist1.item.clear();

Than add new items:
2. Dropdownlist1.item.add("item_name");


你可以使用这个:



ddlAgentName.Items.Clear();

ddlAgentName.DataSource = DTBND.GetAgents(ddlDatabaseName.SelectedValue)

ddlAgentName.DataBind()
You can use this :

ddlAgentName.Items.Clear();
ddlAgentName.DataSource = DTBND.GetAgents(ddlDatabaseName.SelectedValue)
ddlAgentName.DataBind()


这篇关于关于如何附加asp.net下拉列表的任何想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆