asp.net中dropdownlist中绑定数据…

本文探讨了使用sqldatasource插件为dropdownlist绑定数据源时遇到的问题:当RadioButtonList选项更改时,dropdownlist中数据重复加载。文章提供了解决方案,并保持“=请选择=”项不被删除。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我用sqldatasource插件给dropdownlist绑定了数据源,
数据根据RadioButtonList中的选项来显示,代码如下
if (!IsPostBack)
                
                this.DropDownList1.Items.Clear();
                this.DropDownList1.AppendDataBoundItems = true;
                this.DropDownList1.Items.Add(new ListItem("=请选择=", "=请选择="));
                this.DropDownList1.DataValueField = "Kind2";
                this.DropDownList1.DataTextField = "Kind2";
                this.DropDownList1.DataSourceID = "SqlDataSource1";
                this.DropDownList1.DataBind();                       
          
        }
可问题是,每次改变RadioButtonList中的选项后,DropDownList中的数据项就会再次被加入,不同RadioButtonList对应的数据项都显示出来了,还刷新一次就加一次,导致出现重复的项,怎样在不删除“=请选择=”这个项的前提下,解决上面的问题。能给出代码最好
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值