How to freeze an Asp.net gridview header? I am trying to do it in different ways, but not able to.
I am using ASP 2.0 and VS 2010.
Can any one help me?
How to freeze an Asp.net gridview header? I am trying to do it in different ways, but not able to.
I am using ASP 2.0 and VS 2010.
Can any one help me?
i use jquery floatThead
http://mkoryak.github.io/floatThead/#intro
i had to use a bit of jquery to convert to first row to a thead for it to work.
example below:
$(document).ready(function () {
var $theadCols = $("#ContentPlaceHolder1_grdCashflow tr:first-child"),
$table = $("#ContentPlaceHolder1_grdCashflow");
// create thead and append <th> columns
$table.prepend("<thead/>");
$table.find("thead").append($theadCols);
// init stickyHeader
$table.floatThead();
//$table = $("#ContentPlaceHolder1_grdCashflow");
$table.dataTable(
{
"paging": false,
"ordering": false,
"dom":'<"top"fi>rt<"bottom"><"clear">'
}
);
});
If you are ok with Jquery you can try Datatables Jquery plugin
https://datatables.net/extensions/responsive/examples/column-control/fixedHeader.html
After binding the gridview data [c#]
gridviewid.UseAccessibleHeader = true;
gridviewid.HeaderRow.TableSection = TableRowSection.TableHeader;
for jquery
<script>
function pageLoad(sender, args) {
//Your jquery code
$(document).ready(function () {
tableGrid();
});
function tableGrid() {
$("#<%=gridviewID.ClientID%>").dataTable().fnDestroy();
$("#<%=gridviewID.ClientID%>").dataTable({
"sPaginationType": "full_numbers",
"columnDefs": [{
"orderable": false
}],
"aaSorting": [],
info: false,
paging: true,
"oLanguage": { "sSearch": "Search: " },
mark: true,
dom: 'Blfrtip',
buttons: [], fixedHeader: true
});
}
}
</script>
Note : whenever you rebind you data call the javascript funciton from c# code
ScriptManager.RegisterStartupScript(this, this.GetType(), "callheader", "tableGrid();", true);