FineUI 官方论坛
标题:
DropDownList在动态绑定数据时,无法指定.DataSimulateTreeLevelFiel...
[打印本页]
作者:
capfhz
时间:
2017-3-14 09:03
标题:
DropDownList在动态绑定数据时,无法指定.DataSimulateTreeLevelFiel...
DropDownList在初始化时,可以指定.DataSimulateTreeLevelField("TreeLevel"),在.OnSelectedIndexChanged(Url.Action("ddlSheng_SelectedIndexChanged"), "Form1"),事件中,页面中的.DataSimulateTreeLevelField("TreeLevel")无效,
public ActionResult Edit(string id, string nodeID)
{
Sys_Department sys_Department = id == null ? new Sys_Department() : db.Sys_Departments.Find(id);
if (sys_Department == null)
{
return HttpNotFound();
}
string orgnizationID = nodeID == null ? "-1" : nodeID;
sys_Department.sys_Orgnization_ID = sys_Department.ID == null ? orgnizationID : sys_Department.sys_Orgnization_ID;
sys_Department.SortIndex = sys_Department.ID == null ? db.Sys_Departments.Where(m => m.sys_Orgnization_ID == nodeID).Count() + 1 : sys_Department.SortIndex;
ViewBag.ParentID = ResolveDDL(GetSys_DepartmentCoustonTree(nodeID), sys_Department.ParentID);
ViewBag.sys_Orgnization_ID = ResolveDDL(GetSys_OrgnizationCoustonTree(null), null, false);
return View(sys_Department);
}
这是初始化时的数据源
F.DropDownListFor(m => m.sys_Orgnization_ID).Label("所属机构")
.EnableSimulateTree(true)
.DataTextField("Name").DataValueField("ID")
.DataSimulateTreeLevelField("TreeLevel")
.DataEnableSelectField("Enabled")
.DataSource(ViewBag.sys_Orgnization_ID)
.OnSelectedIndexChanged(Url.Action("ddlSheng_SelectedIndexChanged"), "Form1"),
F.DropDownListFor(m => m.ParentID).Label("所属部门")
.EnableSimulateTree(true)
.DataTextField("Name").DataValueField("ID")
.DataSimulateTreeLevelField("TreeLevel")
.DataEnableSelectField("Enabled")
.DataSource(ViewBag.ParentID)
这是前台页面数据
[attach]9883[/attach]
这是所属机构的事件
public ActionResult ddlSheng_SelectedIndexChanged(FormCollection values)
{
var nodeID = values["sys_Orgnization_ID"];
var ddl = UIHelper.DropDownList("ParentID");
ddl.DataSource(ResolveDDL(GetSys_DepartmentCoustonTree(nodeID)).ToArray(),"ID","Name");
ddl.SelectedValue("-1");
return UIHelper.Result();
}
作者:
capfhz
时间:
2017-3-14 09:05
var ddl = UIHelper.DropDownList("ParentID");
ddl.DataSource(ResolveDDL(GetSys_DepartmentCoustonTree(nodeID)).ToArray(),"ID","Name");
ddl下无.DataSimulateTreeLevelField("TreeLevel")方法
作者:
sanshi
时间:
2017-3-14 11:49
可以通过 Source 属性来改变 UIHelper.DropDownList("DropDownList1") 返回的控件属性,类似如下代码:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult btnDataBind_Click(string DropDownList1, string DropDownList1_text)
{
var dropDownList1UI = UIHelper.DropDownList("DropDownList1");
// 通过 Source 设置控件属性
dropDownList1UI.Source.EnableSimulateTree = true;
dropDownList1UI.Source.DataSimulateTreeLevelField = "Level";
dropDownList1UI.Source.DataEnableSelectField = "EnableSelect";
// 绑定数据
dropDownList1UI.DataSource(GetData2(), "Id", "Name");
// 设置选中项
dropDownList1UI.SelectedValue("11");
return UIHelper.Result();
}
复制代码
下个版本,我会增加示例:
[attach]9887[/attach]
[attach]9888[/attach]
作者:
capfhz
时间:
2017-3-15 09:40
OK了,谢谢三师兄的回复
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4