表格中一个列选择值后,联动带出另一个列的值(代码版)

下拉选择仓库,带出仓库的描述在另外一列

因为服务里,设置OnGetValue不生效,所以选择写代码实现。

代码如下:

protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            Grid_OrdersDetails.RowUpdated += new JQGridEventHandler(Grid_OrdersDetailsRowUpdated);行更新事件
        }
        public ResponseData Grid_OrdersDetailsRowUpdated(object sender, JQGridEventArgs args)
        {
            try
            {
                string rowid = args.State.RowID;//行id
                string ws = Convert.ToString((Grid_OrdersDetails.GridContext as BoundContext).GetCell(rowid, "SJ_Warehouse"));//得到变量
                if (string.IsNullOrEmpty(ws))
                {
                    return args.Response;
                }
          //去数据库查 string sql = String.Format(@"select sw.Description from SJ_Warehouse sw where sw.SJ_WarehouseName='{0}'", ws); QueryOptions _queryOptions = new QueryOptions() { QueryType = Camstar.WCF.ObjectStack.QueryType.User, ChangeCount = 0 }; RecordSet recordset; ResultStatus result; var qService = (Page as IForm).Service.GetService<QueryService>(); result = qService.ExecuteAdHoc(sql, _queryOptions, out recordset); DataTable dt = recordset.GetAsExplicitlyDataTable(); if (dt != null && dt.Rows != null && dt.Rows.Count > 0) {
            //查询出来了,赋值 Grid_OrdersDetails.BoundContext.SetCell(rowid, "WarehouseName", dt.Rows[0]["Description"].ToString()); Grid_OrdersDetails.BoundContext.LoadData(); Page.RenderToClient = true; } } catch (Exception ex) { return args.Response; } return args.Response; }

  

 

posted @ 2024-03-04 17:16  我的胖猫叫咪咪  阅读(54)  评论(1编辑  收藏  举报