Hi dof:
以上,如果放在:ScriptManager 和 UpdatePanel 就会失效。
如下:
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="_0000_Popup.WebForm2" %>
<%@ Register Assembly="FarPoint.Web.Spread" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function ScrollToRow(valgridname) {
var rowindex = 0;
if (document.all) {
document.onreadystatechange = function () {
var spread = document.getElementById(valgridname);
rowindex = spread.GetRowCount() - 1;
if (spread.readyState == "complete") {
spread.ScrollTo(rowindex, 0);
spread.SetActiveCell(rowindex, 1);
}
}
}
else {
document.addEventListener("DOMContentLoaded", function () {
var spread = document.getElementById(valgridname);
rowindex = spread.GetRowCount() - 1;
spread.ScrollTo(rowindex, 0);
spread.SetActiveCell(rowindex, 1);
}, false)
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px" Height="200" Width="400">
<CommandBar BackColor="Control" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
ButtonShadowColor="ControlDark">
</CommandBar>
<Sheets>
<FarPoint:SheetView SheetName="Sheet1">
</FarPoint:SheetView>
</Sheets>
</FarPoint:FpSpread>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
namespace _0000_Popup
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FpSpread1.ActiveSheetView.AllowPage = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// 在指定位置插入新行
FpSpread1.ActiveSheetView.AddRows(FpSpread1.ActiveSheetView.RowCount - 1, 1);
// 调用客户端的ScrollTo方法
StringBuilder sb = new StringBuilder();
sb.AppendLine("<script>");
sb.AppendLine("ScrollToRow('FpSpread1');");
sb.AppendLine("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "scroll", sb.ToString());
}
}
}
你可以试下。
麻烦再帮忙看看,因为我界面中需要有Updatepanel.
谢谢! |