June 3rd, 2012

ASP.NET GridView And RepeatColumns(Rows in Multiple Columns) With jQuery

By Default, There is no RepeatColumns property in ASP.NET Gridview to display rows in multiple columns as in DataList control. When Gridview has few columns, It doesn’t take full space of browser. To make good UI, You might need RepeatColumns property. This post explains how to display asp.net GridView rows in multiple columns using jQuery WITHOUT modifying any existing code.


function GridViewRepeatColumns(gridviewid, repeatColumns) {
            //Created By: Brij Mohan(http://techbrij.com)
            if (repeatColumns < 2) {
                alert('Invalid repeatColumns value');
            var $gridview = $('#' + gridviewid);
            var $newTable = $('<table></table>');

            //Append first row in table
            var $firstRow =  $gridview.find('tr:eq(0)'),
            firstRowHTML = $firstRow.html(),
            colLength = $firstRow.children().length;


            //Append first row cells n times
            for (var i = 0; i < repeatColumns - 1; i++) {

            while ($gridview.find('tr').length > 0) {
                var $gridRow = $gridview.find('tr:eq(0)');
               for (var i = 0; i < repeatColumns - 1; i++) {
                   if ($gridview.find('tr').length > 0) {
                   else {
                       for (var j = 0; j < colLength; j++) {
            //update existing GridView

You have to use above method and pass gridviewid and number of repeated columns. suppose your gridview ID is gridSample and have following structure:

gridview jquery asp.net

To create two columns layout, call following in javascript:

GridViewRepeatColumns("<%=gridSample.ClientID %>",2);
gridview jquery asp.net

For Three columns layout:
GridViewRepeatColumns("<%=gridSample.ClientID %>",3);

gridview jquery asp.net

For Four columns layout:
GridViewRepeatColumns("<%=gridSample.ClientID %>",4);

gridview jquery asp.net

Now You see edit and delete functionality is as it is, No need to modify any other server side code.


Here is the HTML rendered demo of 3 columns layout:

Hope, It saves your time.

  • Prowshan

    What if gridview does not have header? In this project always header repeats on each column.

  • ┬áComment line 10 to 20, if gridview doesn’t have header.

  • Prabhatyadav3108

    thanku very much.. from Niki, Gaurang and Prabhat

  • andy

    At what point do i call this function?

  • Dan

    Hi, this is very helpful but I cannot seem to get my script to run past the first few lines. I think it has something to do with where/how I am declaring the script type. Could you give me an example of how this would look inside an asp.net page? (i.e what the tag would look like and if I need anything else to run it successfully.

    Thank you very much!

  • After grid declaration in aspx side, you can call the method OR you can use RegisterStartupScript method.

  • After grid declaration aspx side, You can declare script tag and define the method and call it.

  • Shail

    How to add space between two columns ?

  • Kingsley RTMJ

    Hi Brij, very good one!

    I am finding it hard to make it work on my code.

    Can you brief me how to use this in aspx page or how to call this from code behind?
    I am new to Jquery, sorry!

  • swanand kulkarni

    This code is good for what I m looking for but I m not getting how to include this in our aspx page , so pls will u give some what brief explaination for this.

  • lavneet

    hi.. brij ,
    i am finding it difficult to implement. kindly help out.

  • mukesh patil

    thanx You …my grid working good but first record of grid display duplicate record

  • Zahid Khan

    Dear I used the method but it shows me error: Reference Error: GridiView1 is not define. Please help me how to implement it correctly. Thanks.

  • Santosh Gandhi

    how to show data for a range like 1-10 in one column and 11-20 second column and so on………

    please help me

  • harish madaan

    This code not working for me, where should i call the GridViewRepeatColumns function.. pls help…