Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
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
Comments
n.podbielski 28-Sep-12 6:08am    
Just add collection as data source.

You can use a dictionary to bind
ASP.NET
<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
C#
Dictionary<string,> dictionary = new Dictionary<string,>()
    {
        {"a", "aaa"},
        {"b", "bbb"},
        {"c", "ccc"}
    };
    datalist.DataSource = dictionary;
    datalist.DataBind();
 
Share this answer
 
v2
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
 
Share this answer
 
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,
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900