给你一个我调通vb的。你把它改成C#
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="scroll.aspx.vb" Inherits="code.scroll"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>scroll</title>
<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="WebForm1" method="post" runat="server">
<P><FONT face="Verdana" size="5">Booking DataGrid Items<BR>
</FONT>By: Donny Mack</P>
<div id="div1" style="OVERFLOW: scroll; WIDTH: 600px; POSITION: absolute; HEIGHT: 400px"><asp:datagrid id="DGProducts" runat="server" Width="600px" EnableViewState="False" ForeColor="Black" BackColor="Silver" Font-Names="Verdana" CellPadding="4" Font-Size="Smaller">
<HeaderStyle Font-Size="Small" Font-Bold="True" BorderColor="Black" BackColor="Maroon"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Select" HeaderText="Highlight" CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp:datagrid><FONT face="宋体"></FONT></div>
</form>
</body>
</HTML>
Public Class scroll
Inherits System.Web.UI.Page
Protected WithEvents DGProducts As System.Web.UI.WebControls.DataGrid#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region 'Private designerPlaceholderDeclaration As System.Object
Public bookIndex As Integer = 0 ' The index of the row that should be scrolled to
Public itemCount As Integer = 0 'Counter for the amount of items on the page
Public bookMark As Boolean = True 'Controls whether or not the page is booked Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
'If Not Page.IsPostBack Then
Me.Bind()
'End If
End Sub Private Sub Bind()
DGProducts.DataSource = Me.CreateDataSource(1000)
DGProducts.DataBind() End Sub Private Function CreateDataSource(ByVal count As Integer) As DataTable Dim table As New DataTable()
Dim column As DataColumn = Nothing
Dim row As DataRow = Nothing
Dim iCol As Integer = 0
Dim iRows As Integer = 0
' Create 5 columns
For iCol = 0 To 5 - 1 column = New DataColumn("Column: " + iCol.ToString(), GetType(String))
table.Columns.Add(column) Next ' Create Rows based on count variable
For iRows = 0 To count - 1 row = table.NewRow() For iCol = 0 To 5 - 1 row(iCol) = "Value: " + iCol.ToString() Next table.Rows.Add(row) Next Return table End Function Private Sub InsertScriptBlock() Dim jScript As New System.Text.StringBuilder()
jScript.Append("<script language=""JavaScript"">")
jScript.Append("location.href=""#")
jScript.Append(Me.bookIndex.ToString())
jScript.Append(""";")
jScript.Append("</script>") Me.RegisterClientScriptBlock("Book", jScript.ToString()) End Sub Private Sub DGProducts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DGProducts.ItemDataBound If (bookMark) Then Dim anchor As New LiteralControl()
anchor.Text = "<a name=""" + itemCount.ToString() + """>"
itemCount = itemCount + 1
e.Item.Cells(0).Controls.Add(anchor) If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='white'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='Silver'")
e.Item.Cells(3).Style("cursor") = "hand"
End If End If
End Sub Private Sub DGProducts_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGProducts.ItemCommand If e.CommandName = "Select" Then e.Item.BackColor = Color.White If (bookMark) Then bookIndex = e.Item.ItemIndex
Me.InsertScriptBlock() End If End If
End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="scroll.aspx.vb" Inherits="code.scroll"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>scroll</title>
<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="WebForm1" method="post" runat="server">
<P><FONT face="Verdana" size="5">Booking DataGrid Items<BR>
</FONT>By: Donny Mack</P>
<div id="div1" style="OVERFLOW: scroll; WIDTH: 600px; POSITION: absolute; HEIGHT: 400px"><asp:datagrid id="DGProducts" runat="server" Width="600px" EnableViewState="False" ForeColor="Black" BackColor="Silver" Font-Names="Verdana" CellPadding="4" Font-Size="Smaller">
<HeaderStyle Font-Size="Small" Font-Bold="True" BorderColor="Black" BackColor="Maroon"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Select" HeaderText="Highlight" CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp:datagrid><FONT face="宋体"></FONT></div>
</form>
</body>
</HTML>
Public Class scroll
Inherits System.Web.UI.Page
Protected WithEvents DGProducts As System.Web.UI.WebControls.DataGrid#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region 'Private designerPlaceholderDeclaration As System.Object
Public bookIndex As Integer = 0 ' The index of the row that should be scrolled to
Public itemCount As Integer = 0 'Counter for the amount of items on the page
Public bookMark As Boolean = True 'Controls whether or not the page is booked Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
'If Not Page.IsPostBack Then
Me.Bind()
'End If
End Sub Private Sub Bind()
DGProducts.DataSource = Me.CreateDataSource(1000)
DGProducts.DataBind() End Sub Private Function CreateDataSource(ByVal count As Integer) As DataTable Dim table As New DataTable()
Dim column As DataColumn = Nothing
Dim row As DataRow = Nothing
Dim iCol As Integer = 0
Dim iRows As Integer = 0
' Create 5 columns
For iCol = 0 To 5 - 1 column = New DataColumn("Column: " + iCol.ToString(), GetType(String))
table.Columns.Add(column) Next ' Create Rows based on count variable
For iRows = 0 To count - 1 row = table.NewRow() For iCol = 0 To 5 - 1 row(iCol) = "Value: " + iCol.ToString() Next table.Rows.Add(row) Next Return table End Function Private Sub InsertScriptBlock() Dim jScript As New System.Text.StringBuilder()
jScript.Append("<script language=""JavaScript"">")
jScript.Append("location.href=""#")
jScript.Append(Me.bookIndex.ToString())
jScript.Append(""";")
jScript.Append("</script>") Me.RegisterClientScriptBlock("Book", jScript.ToString()) End Sub Private Sub DGProducts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DGProducts.ItemDataBound If (bookMark) Then Dim anchor As New LiteralControl()
anchor.Text = "<a name=""" + itemCount.ToString() + """>"
itemCount = itemCount + 1
e.Item.Cells(0).Controls.Add(anchor) If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='white'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='Silver'")
e.Item.Cells(3).Style("cursor") = "hand"
End If End If
End Sub Private Sub DGProducts_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGProducts.ItemCommand If e.CommandName = "Select" Then e.Item.BackColor = Color.White If (bookMark) Then bookIndex = e.Item.ItemIndex
Me.InsertScriptBlock() End If End If
End Sub
End Class
解决方案 »
- 怎样把Microsoft.Office.Interop.Excel.ApplicationClass excel创建的文件保存到数据流中
- asp.net中.aspx播放flash问题
- 诸位大拿帮我看下这个加密算法
- 请专家们指点以下程序代码由哪些弊病
- 用table显示数据如何分页,类似商城中的商品浏览页面
- 怎样用编程方式放大或缩小图片?
- 奇怪的问题???
- DataGrid 什么通过实现垂直滚动条(须要列子)(急用!谢谢高手帮助) 在线等
- 怎么做asp.netc# 的管理员认证页面啊..我只要给我看个现成的就可以了.谢谢
- 头痛的问题
- 昨天的问题还是没有解决,SqlConnection的问题
- 100分求助各位高手,能否在服务器端调用javascript函数?
点击其它或按钮是无效。to:river168(海阔天空.net) :<%@Page smartNavigation="true"%>
时,IE字体改变,在Head加了样式单还是一样,估计我的IE
有问题,刚开始执行字体都变成默认值
其实楼上两位仁兄的方法我都用过了,我想换一种用法,就是以上我的代码,运行时出错
希望能得各位大侠帮一下,谢谢^_^....
<body id="thebody">
解决的灵感来自于river168(海阔天空.net) 的
http://www.wintellect.com/resources/faqs/default.aspx?faq_id=1&page=7#6