如何在不使用数据库的情况下绑定数据列表

编程入门 行业动态 更新时间:2024-10-27 17:23:59
本文介绍了如何在不使用数据库的情况下绑定数据列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在不使用数据库的情况下绑定数据列表,就像阅读器或数据集一样,我想通过全局变量或函数绑定数据列表

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,

更多推荐

如何在不使用数据库的情况下绑定数据列表

本文发布于:2023-10-17 11:11:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500721.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   情况下   数据库   数据   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!