找回密码
 立即注册

QQ登录

只需一步,快速开始

a1274918722

论坛元老

12

主题

31

帖子

7922

积分

论坛元老

积分
7922

活字格认证

a1274918722
论坛元老   /  发表于:2013-4-8 09:46  /   查看:6341  /  回复:5
之前的内容在 单元格类型发生变化后消失!!  需求:要求不管单元格的内容是否发生变化,内容始终保留在画面中(值是通过.Text在后台绑定的)

ChangeCellType.rar

20.68 KB, 下载次数: 806

5 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-4-8 17:21:00
沙发
回复 1楼a1274918722的帖子

a1274918722 你好,
Spread ComboBoxCellType 设计如此,当前 Cell 的文本值不是 ComboBoxCellType 子项时,无法保留原始值。
请使用以下代码测是:

  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             if (IsPostBack)
  4.             {
  5.                 return;
  6.             }
  7.             FpSpread1.UseClipboard = false;
  8.             this.FpSpread1.ActiveSheetView.Cells[0, 0].Text = "A";
  9.         }

  10.         protected void btnComBox_Click(object sender, EventArgs e)
  11.         {
  12.             FarPoint.Web.Spread.ComboBoxCellType commbox = new FarPoint.Web.Spread.ComboBoxCellType();
  13.             string[] arr = new string[] { "A", "B" };
  14.             commbox.DataSource = arr;
  15.             this.FpSpread1.ActiveSheetView.Cells[0, 0].CellType = commbox;
  16.         }

  17.         protected void btnText_Click(object sender, EventArgs e)
  18.         {
  19.             FarPoint.Web.Spread.TextCellType text = new FarPoint.Web.Spread.TextCellType();
  20.             this.FpSpread1.ActiveSheetView.Cells[0, 0].CellType = text;
  21.         }
复制代码
回复 使用道具 举报
a1274918722
论坛元老   /  发表于:2013-4-8 18:14:00
板凳
回复 2楼iceman的帖子

版主:
    那段代码不能解决我的问题。
   
    如果在JS中对单元格进行赋值可以么??  我在尝试 但是SetValue这个JS方法报错!!
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-4-9 15:48:00
地板
回复 3楼a1274918722的帖子

通过 js 可以设置值,有两种方法:

  1. <script language="javascript" type="text/javascript">
  2. // <![CDATA[

  3.         function Button1_onclick() {
  4.             //方法1
  5.             var table = this.document.getElementById("FpSpread1_viewport");
  6.             table.rows[0].cells[0].innerText = "test";

  7.             //方法2
  8.             var spread = this.document.getElementById("FpSpread1");
  9.             spread.SetValue(0, 0, "Scott", true);
  10.         }

  11. // ]]>
  12.     </script>
复制代码
回复 使用道具 举报
a1274918722
论坛元老   /  发表于:2013-4-16 15:20:00
5#
回复 4楼iceman的帖子

类型变成combox后单元格中的内容还是不能保留在画面中!!
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-4-17 10:09:00
6#
回复 5楼a1274918722的帖子

a1274918722 你好,

请问“不能保留到画面中”指的是?
正如我们之前提到的,Combo 单元格类型单元格值必须为 Combo 子项,这是默认行为,我们无法更改。所以,通过前台 js 脚本来实现。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部