在运行时的下拉列表中添加项目 [英] Adding Item in the dropdown list in the run time

查看:60
本文介绍了在运行时的下拉列表中添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个下拉列表,我通过使用函数来填充数据表。在调用该函数之后,我想要在drop中调用所有项目(Other)。我试图做到这一点,但它未能给我结果

Hi all
I have a drop down list that I fill with data table by using function does that. After calling that function , I want to all item in the drop called (Other). I tried to make that but it failed to give me the result

select_city();             //the function that retrieve data
if (DT.Columns.Count > 0)
{
    drplst_City.DataSource = DT;
    drplst_City.DataTextField = "Name"
    drplst_City.DataValueField = "Id";
    drplst_City.Items.Add(new ListItem("other", ""));
    drplst_City.DataBind();
}





有什么帮助吗?



谢谢



内联代码更改为代码块,资本化,删除虚假我来自单词嗨 - OriginalGriff [/ edit]



any help ,please?

thanks

[edit]inline code changed to code block, capitalizaion, removed spurious "i"s from teh word "Hi" - OriginalGriff[/edit]

推荐答案

添加自定义项后,您将调用 .DataBind(),这将清除控件。将订单更改为:



You are calling .DataBind() after you add your custom item, which will clear the control. change the order to:

select_city(); //the function that retrieve data
if (DT.Columns.Count > 0)
{
drplst_City.DataSource = DT;
drplst_City.DataTextField = "Name"; drplst_City.DataValueField = "Id";
drplst_City.DataBind();
drplst_City.Items.Add(new ListItem("other", ""));
}


Hope 这个 [ ^ ]也可以给你一个想法。
Hope this[^] may also give you an idea.


DropDownList ddl = new DropDownList()

ddl
DropDownList ddl=new DropDownList()
ddl


这篇关于在运行时的下拉列表中添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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