求固定表头及首列DataGrid 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 什么意思?自定义datagridtablestyle 就是当数据量很大时,自动生成滚动条,并且垂直滚动时Head不动,水平滚动时,第一列不动 //ShowFixedHeader.aspx文件<%@ Page language="c#" Codebehind="ShowFixedHeader.aspx.cs" AutoEventWireup="false" Inherits="bobomousetest.ShowFixedHeader" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <title id="lucky_elove"></title> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0"> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout" leftmargin="0"> <table align="center"> <tr> <td> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" runat="server" cellSpacing="1" cellPadding="2" width="720" border="1" bgcolor="#cc6633" bordercolor="#cc9966" style="FONT-SIZE:9pt;BORDER-BOTTOM:0px"> <TR align="middle"> <TD colspan="2" width="430"><FONT face="宋体"></FONT></TD> <TD width="190" colspan="2"></TD> </TR> <TR align="middle"> <TD width="360" bgcolor="#66cc99"></TD> <TD width="180" bgcolor="white"></TD> <TD width="140" bgcolor="#99cccc"></TD> <TD width="40" bgcolor="#009999"></TD> </TR> </TABLE> <div style="BORDER-RIGHT:0px;PADDING-RIGHT:0px;BORDER-TOP:0px;PADDING-LEFT:0px;PADDING-BOTTOM:0px;MARGIN:0px;OVERFLOW:auto;BORDER-LEFT:0px;WIDTH:736px;PADDING-TOP:0px;BORDER-BOTTOM:0px;HEIGHT:200px"> <asp:DataGrid id="DataGrid1" width="720px" CellPadding="2" CellSpacing="1" BorderColor="#cc9966" Font-Size="9pt" AlternatingItemStyle-BackColor="#6699ff" runat="server" ShowHeader="False" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn DataField="Title"> <ItemStyle Width="360px"></ItemStyle> </asp:BoundColumn> <asp:BoundColumn DataField="CreateDate"> <ItemStyle Width="180px" HorizontalAlign="Center"></ItemStyle> </asp:BoundColumn> <asp:BoundColumn DataField="pid"> <ItemStyle Width="140px" HorizontalAlign="Center"></ItemStyle> </asp:BoundColumn> <asp:BoundColumn DataField="HitCount"> <ItemStyle Width="40px" HorizontalAlign="Center"></ItemStyle> </asp:BoundColumn> </Columns> </asp:DataGrid> </div> </form> </td> </tr> </table> </body></HTML>//ShowFixedHeader.aspx.cs文件using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Data.OleDb;namespace bobomousetest{ /// <summary> /// ShowFixedHeader 的摘要说明。 /// </summary> public class ShowFixedHeader : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Web.UI.HtmlControls.HtmlForm Form1; protected System.Web.UI.HtmlControls.HtmlTable Table1; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 Table1.Rows[0].Cells[0].InnerText="【宪孟会之精彩世界】.NET版本之最新文章"; Table1.Rows[0].Cells[1].InnerText = "文章信息"; Table1.Rows[1].Cells[0].InnerText = "文章标题"; Table1.Rows[1].Cells[1].InnerText = "发布时间"; Table1.Rows[1].Cells[2].InnerText = "所属栏目"; Table1.Rows[1].Cells[3].InnerText = "点击率"; Table1.Rows[0].Style.Add("color", "white"); Table1.Rows[0].Style.Add("font-weight", "bold"); Table1.Rows[0].Cells[0].Attributes.Add("onclick","window.open('http://bobomouse.com/')"); Table1.Rows[0].Cells[0].Style.Add("cursor", "hand"); OleDbConnection cn = new OleDbConnection(); cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("web.mdb"); cn.Open();// string strSQL = "SELECT TOP 30 D.Title,D.CreateDate,S.Title as pid,D.HitCount FROM Document D INNER JOIN Subject S ON D.pid = S.id ORDER BY CreateDate DESC"; string strSQL = "SELECT TOP 30 Title,CreateDate,Title,Title as pid,HitCount FROM Document"; DataSet ds = new DataSet(); OleDbDataAdapter adapter = new OleDbDataAdapter(strSQL, cn); adapter.Fill(ds, "Document"); DataGrid1.DataSource = ds.Tables["Document"].DefaultView; DataGrid1.DataBind(); cn.Close(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion }}//web.mdb文件仅一个Document表,结构如下字段 类型id 自动编号objectGuid 文本Title 文本Author 文本Source 文本Content 备注CreateDate 日期/时间pid 数字HitCount 数字IsPublished 数字Category 文本Keyword 文本 http://dotnet.aspx.cc/ShowDetail.aspx?id=B3F3462D-DC34-41CE-9FEE-6965B2A3D1AD .fixTitle{ /*background: navy; color: white;*/ position: relative; top: expression(this.offsetParent.scrollTop);}用css来定制表头非常简单 http://goody9807.611.cn/Announce/announce.asp?BoardID=2&ID=508&Upflag=1&Num=1 如果在datagrid外面加个div然后设置它的overflow应该可以当数据量超过设置的长度或者宽度的话会出现滚动条固定表头应该有这样的文章 高手看看,这是转义的问题,还是符号冲突? 正则表达的问题(关于""的替换) 请问在三层架构的项目中如何同时使用AspNetPager分页控件和ObjectDataSource控件? aspx文件问题 *︻$▅▆▇◤ [捉拿高手]关于static变量与static方法比较的疑问! 新手请指教 请教一个asp.net中用数据库验证用户登录的问题,多谢! 求生成aspx页面代码! 将一个结构数据存入session之后怎么取用呢? 有谁可以推荐基本学习ASP.NET和C#的书嘛? PostedFile最大能传多大呢? 如何安装使用FreeTextBox
自定义datagridtablestyle
并且垂直滚动时Head不动,水平滚动时,第一列不动
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title id="lucky_elove"></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" leftmargin="0">
<table align="center">
<tr>
<td>
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" runat="server" cellSpacing="1" cellPadding="2" width="720" border="1" bgcolor="#cc6633" bordercolor="#cc9966" style="FONT-SIZE:9pt;BORDER-BOTTOM:0px">
<TR align="middle">
<TD colspan="2" width="430"><FONT face="宋体"></FONT></TD>
<TD width="190" colspan="2"></TD>
</TR>
<TR align="middle">
<TD width="360" bgcolor="#66cc99"></TD>
<TD width="180" bgcolor="white"></TD>
<TD width="140" bgcolor="#99cccc"></TD>
<TD width="40" bgcolor="#009999"></TD>
</TR>
</TABLE>
<div style="BORDER-RIGHT:0px;PADDING-RIGHT:0px;BORDER-TOP:0px;PADDING-LEFT:0px;PADDING-BOTTOM:0px;MARGIN:0px;OVERFLOW:auto;BORDER-LEFT:0px;WIDTH:736px;PADDING-TOP:0px;BORDER-BOTTOM:0px;HEIGHT:200px">
<asp:DataGrid id="DataGrid1" width="720px" CellPadding="2" CellSpacing="1" BorderColor="#cc9966" Font-Size="9pt" AlternatingItemStyle-BackColor="#6699ff" runat="server" ShowHeader="False" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Title">
<ItemStyle Width="360px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="CreateDate">
<ItemStyle Width="180px" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="pid">
<ItemStyle Width="140px" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="HitCount">
<ItemStyle Width="40px" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</div>
</form>
</td>
</tr>
</table>
</body>
</HTML>
//ShowFixedHeader.aspx.cs文件using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;namespace bobomousetest
{
/// <summary>
/// ShowFixedHeader 的摘要说明。
/// </summary>
public class ShowFixedHeader : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.HtmlControls.HtmlTable Table1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Table1.Rows[0].Cells[0].InnerText="【宪孟会之精彩世界】.NET版本之最新文章";
Table1.Rows[0].Cells[1].InnerText = "文章信息";
Table1.Rows[1].Cells[0].InnerText = "文章标题";
Table1.Rows[1].Cells[1].InnerText = "发布时间";
Table1.Rows[1].Cells[2].InnerText = "所属栏目";
Table1.Rows[1].Cells[3].InnerText = "点击率";
Table1.Rows[0].Style.Add("color", "white");
Table1.Rows[0].Style.Add("font-weight", "bold");
Table1.Rows[0].Cells[0].Attributes.Add("onclick","window.open('http://bobomouse.com/')");
Table1.Rows[0].Cells[0].Style.Add("cursor", "hand");
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("web.mdb");
cn.Open();
// string strSQL = "SELECT TOP 30 D.Title,D.CreateDate,S.Title as pid,D.HitCount FROM Document D INNER JOIN Subject S ON D.pid = S.id ORDER BY CreateDate DESC";
string strSQL = "SELECT TOP 30 Title,CreateDate,Title,Title as pid,HitCount FROM Document";
DataSet ds = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(strSQL, cn);
adapter.Fill(ds, "Document");
DataGrid1.DataSource = ds.Tables["Document"].DefaultView;
DataGrid1.DataBind();
cn.Close();
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}//web.mdb文件仅一个Document表,结构如下字段 类型
id 自动编号
objectGuid 文本
Title 文本
Author 文本
Source 文本
Content 备注
CreateDate 日期/时间
pid 数字
HitCount 数字
IsPublished 数字
Category 文本
Keyword 文本
{
/*background: navy;
color: white;*/
position: relative;
top: expression(this.offsetParent.scrollTop);
}用css来定制表头非常简单
固定表头应该有这样的文章