今天做到那个北理工二期的项目,里面刚好有几个dialog需要弄一个默认值,一般是选择启用与否,但是,为了方便用户,最好有一个默认值,所以,增加一个默认值的属性.代码入下:
JS代码:
$(function () {
$('#OfficeInfoList').datagrid({
toolbar: [{
text: '新D?增?',
iconCls: 'icon-add',
handler: function () {
$('#dlg').dialog('open').dialog('setTitle', '新D?增?办°ì公1?室êò信D?息¢');
$('#dlg_form').form('clear')
$('#buildname').combobox('reload', '/Iframes/ClassRoomInfo.aspx?from=sel-Buildname');
$('#departmentname').combobox('reload', '/Iframes/ClassRoomInfo.aspx?from=sel-DepartName');
$('#kt_dk').combobox('reload', '/Iframes/ClassRoomInfo.aspx?from=sel-kt_dk');
$('#dg_dk').combobox('reload', '/Iframes/ClassRoomInfo.aspx?from=sel-dg_dk');
$('#zbdnjd').combobox('reload', '/Iframes/ClassRoomInfo.aspx?from=sel-zbdnjd');
$('#kt_gzfs').combobox('setValue', '1');//这个就是需要给默认值的地方,1表示启用,与下面的值对应.
$('#kt_sfqy').combobox('select', '1');//经过测试,select也可以的
url = '/Iframes/OfficeInfo.aspx?from=sel-add';
}
},
......
html代码:
< div class ="fitem"> < label > 工作方: </ label > < select id ="kt_gzfs" class ="easyui-combobox" name ="kt_gzfs" data-options ="panelHeight:'auto'" style =" padding : 2px; width : 141px;"> < option value ="1" selected ="selected"> 自动</ option > < option value ="0"> 手动 </ option > </ select > </ div >
第二种情况就是:如果是动态获取的数据的话,上面的方法是不可以的,在网上找到另一种方法,代码如下:
前台:
$(document).ready(function () {
$('#BuildingId').combobox('reload', 'TheLatestMeterInfo.aspx?from=sel-Buildname');
$.ajax({
type: "POST",
url: location.href,
success: function () {
var data = $('#BuildingId').combobox('getData');
if (data.length > 0) {
$('#BuildingId').combobox('select', data[0].ID);
var BuildingName = $("#BuildingId").combobox('getValue');
$('#List').datagrid('reload', {
from: 'sel',
BuildingName: BuildingName
})
}
}
});
});
后台:
//加载建筑物信息
if (!string.IsNullOrWhiteSpace(Request["from"]) & Request["from"] == "sel-Buildname")
{
List<BuildingInfoForModel> mList = DataLoader.GetBuildingInfo();
var queryDdlData = from m in mList
select new { ID = m.BuildID, Name = m.BuildName };
Response.Write(JsonHelper.Serialize(queryDdlData));
Response.End();
}