Click here to Skip to main content
12,304,271 members (75,285 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
Posted 27-Sep-12 23:54pm
n.podbielski 28-Sep-12 6:08am
Just add collection as data source.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use a dictionary to bind
<asp:datalist id="datalist" runat="server" datakeyfield="Key" xmlns:asp="#unknown">
        <asp:label runat="server" text="<%# Eval("Value") %>"></asp:label>
Dictionary<string,> dictionary = new Dictionary<string,>()
        {"a", "aaa"},
        {"b", "bbb"},
        {"c", "ccc"}
    datalist.DataSource = dictionary;
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^]

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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, 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, and then populate this list in your DataList UI control.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160530.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100