表格中一个列选择值后,联动带出另一个列的值(代码版)
下拉选择仓库,带出仓库的描述在另外一列

因为服务里,设置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;
}
😘宝子:除非不再醒来,除非太阳不再升起,不然都请你好好生活,挣扎着前进,开心的笑。(●'◡'●)