Click here to Skip to main content
13,248,927 members (45,924 online)
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 23 Mar 2007

DataList Control which will build datalist as per your requirements...

, 23 Mar 2007
Rate this:
Please Sign up or sign in to vote.
custome DataList control

Screenshot - screenshot.jpg


This control will build a DataList control which is Dynamic and you can give Custome properties to it, Like you can select header CSS style, columns width, on which column you want to put sorting functionality and as per properties set you will find that a nice datalist will be displayed with hover effect on each rows, plus sorting functionality on desired columns.

To make it work you just have to give a DataTable for data to be displayed and you have to set some Properties of DataList.


To use this control as per your requirement set these properties...

1. Columns -- you can opetionaly tell how many columns wil be there in your datatable.

2. sortingColumns -- on which columns you need sorting functionality

3. sortingState -- initially which state will be there for sorting for column like ASC or DSEC

4. columnWidths -- you can specify width of each columns..

5. sortingUpImage -- you can give image for sorting as DESC order..

6. sortingDownImage -- you can give image for sorting as ASC order..

7. tableBorder -- you can give border width of your datalist

8. cellAlign -- Alignment of cells..

9. headerCSSClass -- CSS for Header of DataList..

10. ItemRowStyle -- CSS for Item Template...

11. AlterItemRowStyle -- CSS for AlterItem Template...

12. AddSerialNo -- set true if you want serial number as first column...

13. PageSize -- set rows number that will be displayed as page count rows...

Using the code

To use this code just add reference of this DLL file attached with this article.

In your code you have to just set some properties of this control, like given in this sample code, and you have to give DataTable which is containing your data to be displayed in datalist.

first add this lines into web.config...

//in web.config file add these lines...
    <add namespace="MyDataList" assembly="MyDataListControl" 
        tagPrefix="myDL" />
//write this where you want to put this custome DataList...
<myDL:myControl1 runat="server" /> 

//now you can set some properties of control like,
 dtContact = dSet.Tables["Contact"];
                if (dtContact != null)
                    datalistTest.Columns = dtContact.Columns.Count;
                    datalistTest.dataTable = dtContact;
                    datalistTest.tableBorder = 1;                    
                    datalistTest.cellAlign = "left";

                    bool[] sortColumns = new bool[dtContact.Columns.Count];
                    int[] sortState = new int[dtContact.Columns.Count];
                    int[] columnwidths = new int[dtContact.Columns.Count];
                    for (int i = 0; i < dtContact.Columns.Count; i++)
                        sortColumns[i] = true;                       

                        if (i == 0)
                             columnwidths[i] = 60;
                             columnwidths[i] = 100;

                            sortState[i] = 1; //for down image..
                            sortState[i] = 2; // for up image...
                    datalistTest.sortingColumns = sortColumns;
                    datalistTest.sortingState = sortState;
                    datalistTest.columnWidths = columnwidths;

                    datalistTest.AlterItemRowStyle = "Alternate";
                    datalistTest.headerCSSClass = "GridHeader";
If you can not understand how to use this then ask me i will explain you, this control is still in under construnction for better functionality.


Assembly version


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Software Developer
India India
Chirag Patel, a Programmer Analyst in a well known IT company working on .NET Technologies since last 2 years. He is interested in Pure business logic and fuzzy logic. his area of interest is in C#.NET, VB.NET and MSSQL 2005.

catch me on:

You may also be interested in...


Comments and Discussions

QuestionI cant get it in toolbox Pin
sahinci18-Nov-07 8:37
membersahinci18-Nov-07 8:37 
GeneralNew Version Pin
JustChiragPatel24-Mar-07 1:31
memberJustChiragPatel24-Mar-07 1:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 24 Mar 2007
Article Copyright 2007 by JustChiragPatel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid