smartsmile2012通过本文主要向大家介绍了gridview asp.net,asp.net,asp net培训,asp和asp.net的区别,零基础学asp.net等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了asp.net实现固定GridView标题栏的方法。分享给大家供大家参考,具体如下:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
DataTable t = new DataTable();
t.Columns.Add("序号", typeof(int));
t.Columns.Add("材料", typeof(string));
t.Columns.Add("单价", typeof(decimal));
for (int i = 1; i <= 10; i++)
t.Columns.Add("库存" + i, typeof(int));
Random rnd = new Random();
for (int i = 0; i < 80; i++)
{
DataRow row = t.NewRow();
row["序号"] = i + 1;
row["材料"] = Guid.NewGuid().ToString().Substring(0, 13).ToUpper();
row["单价"] = rnd.NextDouble() * 100;
for (int j = 1; j <= 10; j++)
row["库存" + j] = rnd.Next(10000);
t.Rows.Add(row);
}
GridView1.AutoGenerateColumns = false;
foreach (DataColumn c in t.Columns)
{
BoundField bf = new BoundField();
bf.DataField = c.ColumnName;
bf.HeaderText = c.ColumnName;
if (c.DataType == typeof(decimal))
bf.DataFormatString = "{0:#,0.00}";
else if (c.DataType == typeof(int))
bf.DataFormatString = "{0:#,0}";
bf.ItemStyle.HorizontalAlign =
(!string.IsNullOrEmpty(bf.DataFormatString)) ?
HorizontalAlign.Right : HorizontalAlign.Center;
GridView1.Columns.Add(bf);
}
GridView1.DataSource = t;
GridView1.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.altRow { background-color: #ddddff; }
</style>
<link href="superTables.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.3.1.js"></script>
<script type="text/javascript" src="superTables.js"></script>
<script type="text/javascript" src="jquery.superTable.js"></script>
<script type="text/javascript">
$(function() {
$("#GridView1").toSuperTable({ width: "640px", height: "480px", fixedCols: 2 })
.find("tr:even").addClass("altRow");
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" Font-Size="9pt" EnableViewState="false">
</asp:GridView>
</form>
</body>
</html>
</div>
// Super Tables Plugin for jQuery - MIT Style License
// Copyright (c) 2009 Jeffrey Lee --- blog.darkthread.net
//
// A wrapper for Matt Murphy's Super Tables http://www.matts411.com/post/super_tables/
//
// Contributors:
//
////// TO CALL:
// $("...").toSuperTable(options)
//
////// OPTIONS: (order does not matter )
// cssSkin : string ( eg. "sDefault", "sSky", "sOrange", "sDark" )
// headerRows : integer ( default is 1 )
// fixedCols : integer ( default is 0 )
// colWidths : integer array ( use -1 for auto sizing )
// onStart : function ( any this.variableNameHere variables you create here can be used later ( eg. onFinish function ) )
// onFinish : function ( all this.variableNameHere variables created in this script can be used in this function )
// margin, padding, width, height, overflow...: Styles for "fakeContainer"
//
////// Example:
// $("#GridView1").toSuperTable(
// { width: "640px", height: "480px", fixedCols: 2,
// onFinish: function() { alert('Done!'); } })
// jquery.superTable.js
(function($) {
$.fn.extend(
{
toSuperTable: function(options) {
var setting = $.extend(
{
width: "640px", height: "320px",
margin: "10px", padding: "0px",
overflow: "hidden", colWidths: undefined,
fixedCols: 0, headerRows: 1,
onStart: function() { },
onFinish: function() { },
cssSkin: "sSky"
}, options);
return this.each(function() {
var q = $(this);
var id = q.attr("id");
q.removeAttr("style").wrap("<div id='" + id + "_box'></div>");
var nonCssProps = ["fixedCols", "headerRows", "onStart", "onFinish", "cssSkin", "colWidths"];
var container = $("#" + id + "_box");
for (var p in setting) {
if ($.inArray(p, nonCssProps) == -1) {
container.css(p, setting[p]);
delete setting[p];
}
}
var mySt = new superTable(id, setting);
});
}
});
})(jQuery);
</div>
// Super Tables v0.30 - MIT Style License
// Copyright (c) 2008 Matt Murphy --- www.matts411.com
//
// Contributors:
// Joe Gallo
////// TO CALL:
// new superTable([string] tableId, [object] options);
//
////// OPTIONS: (order does not matter )
// cssSkin : string ( eg. "sDefault", "sSky", "sOrange", "sDark" )
// headerRows : integer ( default is 1 )
// fixedCols : integer ( default is 0 )
// colWidths : integer array ( use -1 for auto sizing )
// onStart : function ( any this.variableNameHere variables you create here can be used later ( eg. onFinish function ) )
// onFinish : function ( all this.variableNameHere variables created in this script can be used in this function )
//
////// EXAMPLES:
// var myST = new superTable("myTableId");
//
// var myST = new superTable("myTableId", {
// cssSkin : "sDefault",
// headerRows : 1,
// fixedCols : 2,
// colWidths : [100, 230, 220, -1, 120, -1, -1, 120],
// onStart : function () {
// this.start = new Date();
// },
// onFinish : function () {
// alert("Finished... " + ((new Date()) - this.start) + "ms.");
// }
// });
//
////// ISSUES / NOTES:
// 1. No quirksmode support (officially, but still should work)
// 2. Element id's may be duplicated when fixedCols > 0, causing getElementById() issues
// 3. Safari will render the header row incorrectly if the fixed header row count is 1 and there is a colspan > 1 in one
// or more of the cells (fix available)
////////////superTables.js///////////
var superTable = function (tableId, options) {
/////* Initialize */
options = options || {};
this.cssSkin = options.cssSkin || "";
this.headerRows = parseInt(options.headerRows || "1");
this.fixedCols = parseInt(options.fixedCols || "0");
this.colWidths = options.colWidths || [];
this.initFunc = options.onStart || null;
this.callbackFunc = options.onFinish || null;
this.initFunc && this.initFunc();
/////* Create the framework dom */
this.sBase = document.createElement("DIV");
this.sFHeader = this.sBase.cloneNode(false);
this.sHeader = this.sBase.cloneNode(false);
this.sHeaderInner = this.sBase.cloneNode(false);
this.sFData = this.sBase.cloneNode(false);
this.sFDataInner = this.sBase.cloneNode(false);
this.sData = this.sBase.cloneNode(false);
this.sColGroup = document.createElement("COLGROUP");
this.sDataTable = document.getElementById(tableId);
this.sDataTable.style.margin = "0px"; /* Otherwise looks bad */
if (this.cssSkin !== "") {
this.sDataTable.className += " " + this.cssSkin;
}
if (this.sDataTable.getElementsByTagName("COLGROUP").length > 0) {
this.sDataTable.removeChild(this.sDataTable.getElementsByTagName("COLGROUP")[0]); /* Making our own */
}
this.sParent = this.sDataTable.parentNode;
this.sParentHeight = this.sParent.offsetHeight;
this.sParentWidth = this.sParent.offsetWidth;
/////* Attach the required classNames */
th
您可能想查找下面的文章:
- ASP.NET GridView的Bootstrap分页样式
- asp.net实现固定GridView标题栏的方法(冻结列功能)
- 在ASP.NET 2.0中操作数据之六十四:GridView批量添加数据
- 在ASP.NET 2.0中操作数据之六十三:GridView实现批量删除数据
- 在ASP.NET 2.0中操作数据之六十二:GridView批量更新数据
- 在ASP.NET 2.0中操作数据之五十一:从GridView的页脚插入新记录
- 在ASP.NET 2.0中操作数据之四十九:为GridView控件添加RadioButton
- 在ASP.NET 2.0中操作数据之二十八:GridView里的Button
- 在ASP.NET 2.0中操作数据之十五:在GridView的页脚中显示统计信息
- 在ASP.NET 2.0中操作数据之十二:在GridView控件中使用TemplateField

