如何在不使用数据库的情况下绑定数据列表 [英] How can be bind datalist with out using database
本文介绍了如何在不使用数据库的情况下绑定数据列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不使用数据库的情况下绑定数据列表,就像阅读器或数据集一样,我想通过全局变量或函数绑定数据列表
How can be bind data list with out using database Like reader or data set i want to bind the data list by a global variable or function
推荐答案
使用字典来绑定
You can use a dictionary to bind
<asp:datalist id="datalist" runat="server" datakeyfield="Key" xmlns:asp="#unknown">
<itemtemplate>
<asp:label runat="server" text="<%# Eval("Value") %>"></asp:label>
</itemtemplate>
</asp:datalist>
代码
Code
Dictionary<string,> dictionary = new Dictionary<string,>()
{
{"a", "aaa"},
{"b", "bbb"},
{"c", "ccc"}
};
datalist.DataSource = dictionary;
datalist.DataBind();
您可以使用实现IDictionary和事件DataSet,DataTable的任何集合对象,自定义对象,字典或对象.
看一下链接,这将使您对绑定有一个清晰的认识
详细的数据绑定教程 [
You can use any collection object, custom object, dictionary or object that implements IDictionary and event DataSet, DataTable.
Have a look into the link which will give you fair idea on bindings
A Detailed Data Binding Tutorial[^]
cheers
正如Sandip所说,您可以使用任何IDictionary,数组,集合等.实现要在DataList或DataGrid中填充的IEnumerable接口的任何内容.
您可以使用泛型,IDictionary,IList,HashTables,IList< t> ;,列表无穷无尽.
如果您创建实现通用接口的对象层次结构,例如IMyObject和此接口将属性Value定义为String,将Key定义为String等,可以在List< imyobject>中返回实现此接口的所有对象,然后在DataList UI控件中填充此列表.
问候
Hi,
As Sandip said, you can use any IDictionary, array, collections, etc; anything that implements the IEnumerable interface to be populated in a DataList or DataGrid.
You can use Generics, IDictionary, IList, HashTables, IList<t>, the list is endless..
If you create a hierarchy of Objects that implements a common interface e.g. IMyObject and this interface defines the property Value as String, Key as String, etc., all objects that implement this interface can by returned in a List<imyobject>, and then populate this list in your DataList UI control.
Regards,
这篇关于如何在不使用数据库的情况下绑定数据列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文