How to add responsive behavior in asp: gridview

I want it to asp gridviewdisplay responsive behavior like an html table with a CSS type without too much table as here http://bootsnipp.com/snippets/featured/no-more-tables-respsonsive-table .

Is there any way to achieve it.

I tried one way before to replace my gridview with an html table and apply the no-more-table style from the code behind. But I do not want to do this, because I want all the functions offeredasp:GridView.

+4
source share
1 answer

I wrote my own css to achieve this feature. To use my code, follow these steps:

1: GridView Id no-more-gridView

<section id="no-more-gridView">
    <asp:GridView..>
    .
    </asp:GridView>
</section>

2. ( RowDataBound), ,

e.Row.Cells[0].Attributes["data-title"] = "Col1Name";
e.Row.Cells[1].Attributes["data-title"] = "Col2Name";
e.Row.Cells[2].Attributes["data-title"] = "Col3Name";
.
.

3. , , . media query, , , , .

/*  Author     : Vinay
    Description: Responsive GridView
*/

    /* Force gridview to not be like gridview anymore */
    #no-more-gridView table, 
    #no-more-gridView thead, 
    #no-more-gridView tbody, 
    #no-more-gridView th, 
    #no-more-gridView td, 
    #no-more-gridView tr { 
        display: block; 
    }
    /* Hide table headers (but not display: none;, for accessibility) */
    #no-more-gridView .table_column_head > * { 
        display:none;
    }
    #no-more-gridView tr { all: revert;border: 2px solid #ccc;height:auto !important;}
    #no-more-gridView td { 
        /* Behave  like a "row" */
        border: none;
        border-bottom: 1px solid #eee; 
        position: relative;
        padding-left: 50%; 
        white-space: normal;
        text-align:left;
        padding-bottom: 1em;
    }
    #no-more-gridView td:before { 
        /* Now like a table header */
        position: absolute;
        /* Top/left values mimic padding */
        left: 6px;
        width: 45%; 
        padding-right: 10px; 
        white-space: nowrap;
        text-align:left;
        font-weight: bold;
    }
    /*
    Label the data
    */
    #no-more-gridView td:before { content: attr(data-title); }
+5

Source: https://habr.com/ru/post/1661019/


All Articles