Click here to Skip to main content
15,671,985 members
Articles / Web Development / ASP.NET
Posted 23 Mar 2007


10 bookmarked

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

Rate me:
Please Sign up or sign in to vote.
2.00/5 (4 votes)
23 Mar 2007GPL32 min read
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)

Written By
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:

Comments and Discussions

QuestionI cant get it in toolbox Pin
sahinci18-Nov-07 7:37
sahinci18-Nov-07 7:37 
GeneralNew Version Pin
JustChiragPatel24-Mar-07 0:31
JustChiragPatel24-Mar-07 0:31 
Sorry guys i forgot to upload screen shot of example... but never mind i have developed a new version o control with paging functionality and firt,last,next,previous page functionality...will upload that version soon...

Chirag Patel

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.