找回密码
 立即注册

QQ登录

只需一步,快速开始

一杯沧海cc

论坛元老

3

主题

11

帖子

4887

积分

论坛元老

积分
4887

活字格认证

最新发帖
一杯沧海cc
论坛元老   /  发表于:2013-6-5 13:19  /   查看:6151  /  回复:6
前台的js代码
  1. <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
  2.    <script type ="text/javascript" language="javascript">
  3.        function DivisionChanged() {
  4.            var cell = document.getElementById(cbox);
  5.            var row = cell.ActiveRow;
  6.            var col = cell.ActiveCol;
  7.            cell.EndEdit();
  8.            cell.UpdatePostbackData();
  9.            cell.CallBack("DivisionChanged," + row.toString() + "," + col.toString());
  10.        }     
  11.     </script>
  12.     <script type ="text/javascript" language="javascript">
  13.         function DepartmentChanged() {
  14.             var cell = document.getElementById(cbox);
  15.             var row = cell.ActiveRow;
  16.             var col = cell.ActiveCol;
  17.             cell.EndEdit();
  18.             cell.UpdatePostbackData();
  19.             cell.CallBack("DepartmentChanged," + row.toString() + "," + col.toString());
  20.         }
  21.     </script>
  22. </asp:Content>
复制代码

6 个回复

倒序浏览
一杯沧海cc
论坛元老   /  发表于:2013-6-5 13:24:00
沙发
后台combobox的传值的代码
  1. ComboBoxCellType cobDivison = new ComboBoxCellType();
  2.             cobDivison.ShowButton = true;
  3.             cobDivison.UseValue = true;
  4.             DataTable resultDivisionDt = departmentdV.ToTable(&quot;DEPARTMENT&quot;, true, &quot;HEAD_OFFICE_CODE&quot;, &quot;HEAD_OFFICE_NAME&quot;);
  5.             cobDivison.DataSource = resultDivisionDt;
  6.             cobDivison.DataTextField = &quot;HEAD_OFFICE_NAME&quot;;
  7.             cobDivison.DataValueField = &quot;HEAD_OFFICE_CODE&quot;;
  8.             DataRow dtrDivision = resultDivisionDt.NewRow();
  9.             dtrDivision[cobDivison.DataTextField] = &quot;&quot;;
  10.             dtrDivision[cobDivison.DataValueField] = &quot;00&quot;;
  11.             resultDivisionDt.Rows.InsertAt(dtrDivision, 0);
  12.             //js            
  13.             string js = &quot;var cbox= '&quot; + FpSpread1.ClientID + &quot;';&quot;;
  14.             ClientScript.RegisterStartupScript(this.GetType(), &quot;onStartUpScript&quot;, js, true);
  15.             cobDivison.OnClientChanged = &quot;return DivisionChanged();&quot;;
  16.             FpSpread1.Sheets[0].Columns[5].CellType = cobDivison;
  17.             ComboBoxCellType cobDepartment = new ComboBoxCellType();
  18.             cobDepartment.ShowButton = true;
  19.             cobDepartment.UseValue = true;
  20.             DataTable resultDepartmentDt = departmentdV.ToTable(&quot;DEPARTMENT&quot;, true, &quot;OFFICE_CODE&quot;, &quot;OFFICE_NAME&quot;);
  21.             cobDepartment.DataSource = resultDepartmentDt;
  22.             cobDepartment.DataTextField = &quot;OFFICE_NAME&quot;;
  23.             cobDepartment.DataValueField = &quot;OFFICE_CODE&quot;;
  24.             DataRow dtrDepart = resultDepartmentDt.NewRow();
  25.             dtrDepart[cobDepartment.DataTextField] = &quot;&quot;;
  26.             dtrDepart[cobDepartment.DataValueField] = &quot;00&quot;;
  27.             resultDepartmentDt.Rows.InsertAt(dtrDepart, 0);
  28.             FpSpread1.Sheets[0].Columns[6].CellType = cobDepartment;

  29.             ComboBoxCellType cobGroup = new ComboBoxCellType();
  30.             cobGroup.ShowButton = true;
  31.             cobGroup.UseValue = true;
  32.             DataTable resultGroupDt = departmentdV.ToTable(&quot;DEPARTMENT&quot;, true, &quot;GROUP_CODE&quot;, &quot;GROUP_NAME&quot;);
  33.             cobGroup.DataSource = resultGroupDt;
  34.             cobGroup.DataTextField = &quot;GROUP_NAME&quot;;
  35.             cobGroup.DataValueField = &quot;GROUP_CODE&quot;;
  36.             DataRow dtrGroup = resultGroupDt.NewRow();
  37.             dtrGroup[cobGroup.DataTextField] = &quot;&quot;;
  38.             dtrGroup[cobGroup.DataValueField] = &quot;00&quot;;
  39.             resultGroupDt.Rows.InsertAt(dtrGroup, 0);
  40.             FpSpread1.Sheets[0].Columns[7].CellType = cobGroup;

  41.             FpSpread1.SaveChanges();
复制代码
回复 使用道具 举报
一杯沧海cc
论坛元老   /  发表于:2013-6-5 13:27:00
板凳
当第一个或者第二个combobox的值改变时js调用的方法。
  1. protected void FpSpread1_OnButtonCommand(object sender, SpreadCommandEventArgs e)
  2.         {
  3.             FpSpread1.SaveChanges();
  4.             switch (e.CommandName)
  5.             {
  6.                     case &quot;DivisionChanged&quot;:
  7.                     Point cellDivision = (Point)e.CommandArgument;
  8.                     int divisionId = Convert.ToInt32(this.FpSpread1.ActiveSheetView
  9.                         .Cells[(cellDivision.X + this.FpSpread1.CurrentPage * 15), cellDivision.Y].Value.ToString());
  10.                     DataTable dt = (DataTable)Session[&quot;DEPARTMENT&quot;];
  11.                     DataView office = dt.DefaultView;
  12.                     office.RowFilter = string.Format(&quot;HEAD_OFFICE_CODE = {0}&quot;,divisionId);
  13.                     DataTable resultOfficeDt = office.ToTable(&quot;DEPARTMENT&quot;, true, &quot;OFFICE_CODE&quot;, &quot;OFFICE_NAME&quot;);
  14.                     DataTable resultGroupDt = office.ToTable(&quot;DEPARTMENT&quot;, true, &quot;GROUP_CODE&quot;, &quot;GROUP_NAME&quot;);
  15.                     ComboBoxCellType cobDepartment = new ComboBoxCellType();
  16.                     cobDepartment.ShowButton = true;
  17.                     cobDepartment.DataSource = resultOfficeDt;
  18.                     cobDepartment.DataTextField = &quot;OFFICE_NAME&quot;;
  19.                     cobDepartment.DataValueField = &quot;OFFICE_CODE&quot;;
  20.                     cobDepartment.UseValue = true;
  21.                     cobDepartment.OnClientChanged = &quot;return DepartmentChanged();&quot;;
  22.                     FpSpread1.ActiveSheetView
  23.                         .Cells[(cellDivision.X + this.FpSpread1.CurrentPage * 15), cellDivision.Y + 1].CellType = cobDepartment;
  24.                      ComboBoxCellType cobGroup = new ComboBoxCellType();
  25.                     cobGroup.ShowButton = true;
  26.                     cobGroup.UseValue = true;
  27.                     cobGroup.DataSource = resultGroupDt;
  28.                     cobGroup.DataTextField = &quot;GROUP_NAME&quot;;
  29.                     cobGroup.DataValueField = &quot;GROUP_CODE&quot;;
  30.                     FpSpread1.ActiveSheetView
  31.                         .Cells[(cellDivision.X + this.FpSpread1.CurrentPage * 15), cellDivision.Y + 2].CellType = cobGroup;
  32.                     break;

  33.                     case &quot;DepartmentChanged&quot;:
  34.                     Point cellDepart = (Point)e.CommandArgument;
  35.                     int divisionGetId = Convert.ToInt32(this.FpSpread1.ActiveSheetView
  36.                         .Cells[(cellDepart.X + this.FpSpread1.CurrentPage * 15), cellDepart.Y - 1].Value.ToString());
  37.                     int departGetId = Convert.ToInt32(this.FpSpread1.ActiveSheetView
  38.                         .Cells[(cellDepart.X + this.FpSpread1.CurrentPage * 15), cellDepart.Y].Value.ToString());
  39.                     DataTable dtDepart = (DataTable)Session[&quot;DEPARTMENT&quot;];
  40.                     DataView group = dtDepart.DefaultView;
  41.                     group.RowFilter = string.Format(&quot;HEAD_OFFICE_CODE = {0} AND OFFICE_CODE = {1}&quot;, divisionGetId, departGetId);
  42.                     ComboBoxCellType comGroup = new ComboBoxCellType();
  43.                     comGroup.ShowButton = true;
  44.                     comGroup.UseValue = true;
  45.                     comGroup.DataSource = dtDepart;
  46.                     comGroup.DataTextField = &quot;GROUP_NAME&quot;;
  47.                     comGroup.DataValueField = &quot;GROUP_CODE&quot;;
  48.                     FpSpread1.ActiveSheetView
  49.                         .Cells[(cellDepart.X + this.FpSpread1.CurrentPage * 15), cellDepart.Y + 1].CellType = comGroup;
  50.                     break;
  51.                 default:
  52.                     break;
  53.             }
  54.         }
复制代码
回复 使用道具 举报
一杯沧海cc
论坛元老   /  发表于:2013-6-5 13:52:00
地板
现在遇到的问题是当触发js的事件后,能够进入FpSpread1_OnButtonCommand方法,其他combobox的数据也能够变成级联后的数据。但是在页面显示的时候画面的焦点会一直固定在所触发js事件的combobox上,其他combobox的数据不能显示正确的数据,但是传值的时候数据时正确的。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-6-5 18:39:00
5#
回复 4楼一杯沧海cc的帖子

不好意思,能否麻烦你上传 Demo 上来?我使用你的代码无法重现问题
回复 使用道具 举报
一杯沧海cc
论坛元老   /  发表于:2013-6-7 08:24:00
6#
这个问题也已经搞定了,应该是之前我把spread属性设置的代码都写在了pageload里面了。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-6-7 17:50:00
7#
回复 6楼一杯沧海cc的帖子

好的 感谢反馈
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部