Click here to Skip to main content
Rate this: bad
good
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 28-Sep-12 0:54am
Comments
n.podbielski at 28-Sep-12 6:08am
   
Just add collection as data source.
Rate this: bad
good
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">
    <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();
  Permalink  
v2
Rate this: bad
good
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[^]
 
cheers
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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, 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.
 
Regards,
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 213
1 ProgramFOX 205
2 Sergey Alexandrovich Kryukov 158
3 Peter Leow 140
4 Dave Kreskowiak 101
0 OriginalGriff 288
1 ProgramFOX 165
2 Peter Leow 130
3 Sergey Alexandrovich Kryukov 95
4 Fredrik Bornander 85


Advertise | Privacy | Mobile
Web03 | 2.8.150301.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2015
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