Net*_*yth 4 c# asp.net gridview
我想要asp gridview显示响应行为,就像html表所做的那样,没有更多表css样式,如http://bootsnipp.com/snippets/featured/no-more-tables-respsonsive-table所示.
有没有办法实现它.
我之前尝试过一种方法,即用html表替换我的gridview,并从后面的代码中应用no-more-table样式.但我不想这样做,因为我想要提供的所有功能asp:GridView.
我已经编写了自定义css来实现此功能.要使用我的代码,请按照以下步骤操作,
步骤1:将您的GridView包含在Id为as-more-gridView的部分中,如下所示
<section id="no-more-gridView">
<asp:GridView..>
.
</asp:GridView>
</section>
Run Code Online (Sandbox Code Playgroud)
Step2:从后面的代码(在RowDataBound函数内)为每个单元格分配一个data-title属性,如下所示,
e.Row.Cells[0].Attributes["data-title"] = "Col1Name";
e.Row.Cells[1].Attributes["data-title"] = "Col2Name";
e.Row.Cells[2].Attributes["data-title"] = "Col3Name";
.
.
Run Code Online (Sandbox Code Playgroud)
第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); }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2180 次 |
| 最近记录: |