ShowFixHeader.aspx
1@ Page Language="vb" EnableViewState="False" AutoEventWireup="false" Codebehind="ShowFixHeader.aspx.vb" Inherits="vb1.ShowFixHeader"
1<html>
2<head>
3<title id="northsnow_title" runat="server"></title>
4<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR"/>
5<meta content="Visual Basic 7.0" name="CODE_LANGUAGE"/>
6<meta content="JavaScript" name="vs_defaultClientScript"/>
7<meta content=" http://schemas.microsoft.com/intellisense/ie5 " name="vs_targetSchema"/>
8</head>
9<body leftmargin="0" ms_positioning="GridLayout">
10<table align="center">
11<tr>
12<td>
13<form id="Form1" method="post" runat="server">
14<table bgcolor="#cc6633" border="1" bordercolor="#cc9966" cellpadding="2" cellspacing="1" id="Table1" runat="server" style="FONT-SIZE:9pt;BORDER-BOTTOM:0px" width="720">
15<tr align="center">
16<td colspan="2" width="430"></td>
17<td colspan="2" width="190"></td>
18</tr>
19<tr align="center">
20<td bgcolor="#66cc99" width="360"></td>
21<td bgcolor="white" width="180"></td>
22<td bgcolor="#99cccc" width="140"></td>
23<td bgcolor="#009999" width="40"></td>
24</tr>
25</table>
26<div style="BORDER:0px;PADDING:0px;MARGIN:0px;OVERFLOW:auto;WIDTH:736px;HEIGHT:200px">
27<asp:datagrid alternatingitemstyle-backcolor="#6699ff" autogeneratecolumns="False" bordercolor="#cc9966" cellpadding="2" cellspacing="1" font-size="9pt" id="DataGrid1" runat="server" showheader="False" width="720px">
28<columns>
29<asp:boundcolumn datafield="Title">
30<itemstyle width="360px"></itemstyle>
31</asp:boundcolumn>
32<asp:boundcolumn datafield="CreateDate">
33<itemstyle horizontalalign="Center" width="180px"></itemstyle>
34</asp:boundcolumn>
35<asp:boundcolumn datafield="Author">
36<itemstyle horizontalalign="Center" width="140px"></itemstyle>
37</asp:boundcolumn>
38<asp:boundcolumn datafield="HitCount">
39<itemstyle horizontalalign="Center" width="40px"></itemstyle>
40</asp:boundcolumn>
41</columns>
42</asp:datagrid>
43</div>
44</form>
45</td>
46</tr>
47</table>
48</body>
49</html>
ShowFixHeader.aspx.vb
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class ShowFixHeader
Inherits System.Web.UI.Page
Protected WithEvents Table1 As System.Web.UI.HtmlControls.HtmlTable
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents northsnow_title As HtmlControls.HtmlGenericControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
1<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
2End Sub
3Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
4'CODEGEN: This method call is required by the Web Form Designer
5'Do not modify it using the code editor.
6InitializeComponent()
7End Sub
8#End Region
9Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
10northsnow_title.InnerText = "NorthSnow Home - 跨栏表头,滚动表体的DataGrid的实现"
11Table1.Rows(0).Cells(0).InnerText = "NorthSnow Home Article"
12Table1.Rows(0).Cells(1).InnerText = "VB.net + Asp.Net"
13Table1.Rows(1).Cells(0).InnerText = "文章标题"
14Table1.Rows(1).Cells(1).InnerText = "发布时间"
15Table1.Rows(1).Cells(2).InnerText = "文章作者"
16Table1.Rows(1).Cells(3).InnerText = "点击率"
17Table1.Rows(0).Style.Add("color", "white")
18Table1.Rows(0).Style.Add("font-weight", "bold")
19Table1.Rows(0).Cells(0).Attributes.Add("onclick", "window.open('http://blog.csdn.net/precipitant/')")
20Table1.Rows(0).Cells(0).Style.Add("cursor", "hand")
21Try
22Dim cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Test.mdb")
23Dim cn As New OleDbConnection(cnString)
24cn.Open()
25Dim strSQL As String = "SELECT TOP 30 Title,CreateDate,Author,HitCount " + "FROM Document ORDER BY CreateDate DESC"
26Dim cmd As New OleDbCommand(strSQL, cn)
27DataGrid1.DataSource = cmd.ExecuteReader
28DataGrid1.DataBind()
29cn.Close()
30cn = Nothing
31Catch eOle As OleDbException
32Response.Write("产生错误:" + eOle.Message)
33End Try
34End Sub
35Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
36ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
37If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
38If e.Item.Cells(0).Text.Length > 20 Then
39e.Item.Cells(0).Attributes.Add("Title", e.Item.Cells(0).Text)
40e.Item.Cells(0).Text = e.Item.Cells(0).Text.Substring(0, 20) + "…"
41End If
42e.Item.Cells(1).Text = Format(System.Convert.ToDateTime(e.Item.Cells(1).Text), "yyyy年M月d日 h点m分s秒")
43End If
44End Sub
45End Class</system.diagnostics.debuggerstepthrough()>