如何创建下拉列表项运行时? [英] how to create dropdown list item runtime?
本文介绍了如何创建下拉列表项运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个新鲜的
i要求我有两个下拉列表,一个包含分支。(即Mpc,Bipc,cec等)其他一个包含部分(A,B,C) )在将来我想动态添加部分如何帮助我。
谢谢
i'am a fresher
i have a requirement that i have two dropdown lists one is containing Branch.(i.e Mpc,Bipc,cec etc)other one is containing sections(A,B,C)in the future i want to add section's dynamically how to do that Help me.
Thanks
推荐答案
阅读文档怎么样: 如何:在列表Web服务器控件中添加项目[< a href =http://msdn.microsoft.com/en-us/library/14atsyf5(v=vs.85).aspx\"target =_ blanktitle =New Window> ^ ]?
What about reading the documentation: "How to: Add Items in List Web Server Controls"[^]?
使用System.Collections.Generics;
...
List< listitem> items = new List< listitem>();
items.Add(new ListItem(Item 2,Value 2));
items.Add(new ListItem(Item 1,Value 1));
items.Add(new ListItem(Item 3,Value 3));
下拉列表.Items.AddRange(items.ToArray());
using System.Collections.Generics;
...
List<listitem> items = new List<listitem>();
items.Add(new ListItem("Item 2", "Value 2"));
items.Add(new ListItem("Item 1", "Value 1"));
items.Add(new ListItem("Item 3", "Value 3"));
dropdown.Items.AddRange(items.ToArray());
*在数据库中创建一个表来存储节值
*将该节映射到某些关系中的分支名称。
*从表格中读取该部分并分配到下拉列表。
* create a table in database to store the section value
* map the section to the branch name in some relation.
* read the section from the table and assign to the drop down list.
string[] sections = objDataLayer.GetSections(); // ADO code to read sections
ddlSection.DataSource = sections;
ddlSection.DataBind();
以后你只能在数据库中添加或删除,无需修改代码。
如果你遇到任何问题,发表评论..
in future you can add or delete in the database only, no need to modify the code.
if you face any issues on this, post a comment..
这篇关于如何创建下拉列表项运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文