老师请帮看下如何修改能使用回车校验输入:
1、后台protected override void Render(HtmlTextWriter writer)
{
Table viewPort = this.FpSpread1.FindControl("viewport") as Table;
viewPort.Attributes.Add("onclick", "clickOnSpread()");
//viewPort.Attributes.Add("onkeypress", "onUpdateButtonClick()");
base.Render(writer);
}
2、前台:
function clickOnSpread() {
//alert("单击");
var spread1 = document.getElementById("<%=FpSpread1.ClientID %>");
spread1.Update(); // updated to server
spread1.CallBack("getInfo");
}
3、后台只能通过单击单元格后能触发校验事件:
protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
if (e.CommandName == "getInfo")
{
FpSpread1.Sheets[0].ColumnHeader.Cells[0, 1].Text = "mingcneg";
int activeRow = this.FpSpread1.ActiveSheetView.ActiveRow;
int activeCol = this.FpSpread1.ActiveSheetView.ActiveColumn;
string cellText = this.FpSpread1.ActiveSheetView.Cells[activeRow, activeCol].Text;
SqlConnection Sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["db_sbglConnectionString"].ConnectionString);
Sqlcon.Open();
sqlStr = "Select * From W_Department where DepartmentNo='" + cellText + "'";
Cmd = new SqlCommand(sqlStr, Sqlcon);
SqlDataReader Dr = Cmd.ExecuteReader();
if (Dr.Read())
{
this.FpSpread1.ActiveSheetView.Cells[activeRow, activeCol+1].Text = Dr["DepartmentName"].ToString();
ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('代码正确!');</script>");
}
else
{
this.FpSpread1.ActiveSheetView.Cells[activeRow, activeCol + 1].Text = "代码错误!";
ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('代码错误!');</script>");
}
Dr.Close ();
Dr.Dispose ();
Cmd.Dispose ();
Sqlcon.Close ();
Sqlcon.Dispose ();
}
}
此段代码中ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('代码错误!');</script>");语句为何不执行?
4、前台下列代码只能按回车切换单元格
//回车键在单元格中切换
window.onload = function () {
var spread1 = document.getElementById("<%=FpSpread1.ClientID %>");
spread1.AddKeyMap(13, false, false, false, function () {
var ss = spread1;
ss.MoveToNextCell(true);
});
}
如何完善能在单元格中输入代码按回车后激发校验事件?
|