可以从写Add的默认行为,然后在后台完成初值的设置,比如以下代码:
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("编号");
- dt.Columns.Add("名称");
- dt.Columns.Add("创建人");
- dt.Columns.Add("创建时间");
- dt.Rows.Add(10001, "Spread", "葡萄城控件", DateTime.Now);
- FpSpread1.DataSource = dt;
- FpSpread1.ActiveSheetView.Columns[3].Width = 200;
- }
- }
- protected override void Render(HtmlTextWriter writer)
- {
- WebControl add = FpSpread1.FindControl("Add") as WebControl;
- if (add != null)
- {
- add.Attributes.Add("onclick","return CAdd();");
- }
- base.Render(writer);
- }
- protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
- {
- if (e.CommandName == "CAdd")
- {
- int row = FpSpread1.ActiveSheetView.RowCount;
- FpSpread1.ActiveSheetView.Rows.Add(row, 1);
-
- FpSpread1.ActiveSheetView.Cells[row, 0].Value = Convert.ToInt32(FpSpread1.ActiveSheetView.Cells[row - 1, 0].Value.ToString()) + 1;
- FpSpread1.ActiveSheetView.Cells[row, 2].Value = "葡萄城控件";
- FpSpread1.ActiveSheetView.Cells[row, 3].Value = DateTime.Now;
- }
- }
复制代码
- <script type="text/javascript" language="javascript">
- function CAdd() {
- FpSpread1.CallBack("CAdd");
- }
- </script>
复制代码
7226_DefaultValue.zip
(9.71 KB, 下载次数: 1154)
|