在asp.net中从数据库填充列表框? [英] Populate Listbox from database in asp.net?
本文介绍了在asp.net中从数据库填充列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库中填充一个列表框,而数据库中的值是逗号分隔的。
我在表格列中有值发烧,咳嗽。
请指导我如何在列表框中填充这些项目?
我打算以这样的方式填充每个项目应该出现在列表框的separete行中。
感谢提前
解决方案
您可以将逗号分隔值拆分为字符串数组,然后将数组指定为DataSource
到ListBox
。
例如:
< pre lang =midl> string commaSeperatedData = data1 ,DATA2,DATA3\" 跨度>;
ListBox1.DataSource = commaSeperatedData.Split(',');
ListBox1.DataBind();
Hi,
I want to populate a listbox from databse while values in databse are comma separated.
I have values in the table columns like this "fever, cough".
Please guide me as to how I can populate these items in listbox?
I intend to populate in such a way that each item should appear in separete row in the listbox.
Thanks in Advance
解决方案
You can split the comma seperated values into a string array and you can assign the array as aDataSource
to theListBox
.
For example:
string commaSeperatedData = "data1,data2,data3"; ListBox1.DataSource = commaSeperatedData.Split(','); ListBox1.DataBind();
这篇关于在asp.net中从数据库填充列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文