kendo UI gridview绑定下拉框示例

注意:读取时若想下拉框正确显示,必须返回的是key,value值的对象,针对下拉框取值为空的情况,切记要设置上  optionLabel: "请选择",此项,否则可能取不到值


<asp:Content ID="HeaderContent" ContentPlaceHolderID="head" runat="Server">

    <title></title>
    <link href="../css/kendo/kendo.common.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/kendo/kendo.default.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/normal.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../JS/kendo/kendo.web.min.js"></script>
    <style type="text/css">
        ul, li
        {
            margin: 0px 5px;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            var pageUrl = window.location.href;
            var pageName = pageUrl.split("/");
            if (pageName[3].toLowerCase() == "sysmanage") {
                $('#sysmanage').css({ "background-image": "url(../images/current-bg.gif)", "background-repeat": "repeat-x", "background-position": "top left", "color": "#ffffff" });
            }
        });
    </script>
    <script type="text/x-kendo-template" id="template">
        <div class="buildingTab">
            <ul>
                <li class="k-state-active">
                   建筑物信息
                </li>
            </ul>
        <div>
            <div class="buildingGrid"></div>
        </div>
    </script>
    <script type="text/javascript">

        var sellectedCityID;
        var sellectedBuildingFuncID;
        var sellectedSerialNumber;

        var categories;
        var categoriesFunc;
        var partData; //是甲方还是乙方

        $(document).ready(function () {

            partData = [
                        { IsAOrBWay: "甲方", IsAOrBWayValue: "A" },
                        { IsAOrBWay: "乙方", IsAOrBWayValue: "B" }
                    ];

            bindBuildingFunc();
            Bind();

            $("#btnSelect").click(function () {
                $("#noteGrid").empty();
                Bind();
            });

            $.ajax({
                type: "POST",
                url: "UKeyApplyHasReview.aspx/LoadCityArea",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    categories = jQuery.parseJSON(msg.d);
                }
            });

            $.ajax({
                type: "POST",
                url: "UKeyApplyHasReview.aspx/LoadBuildFunc",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    categoriesFunc = jQuery.parseJSON(msg.d);
                }
            });

            function Bind() {

                var element = $("#noteGrid").kendoGrid({
                    dataSource: {
                        transport: {
                            dataType: "json",
                            read: {
                                type: "POST",
                                url: "UKeyApplyHasReview.aspx/LoadNodeListInfo",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json"
                            },
                            update: {
                                type: "POST",
                                url: "UKeyApplyHasReview.aspx/updateNode",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json"
                            },
                            destroy: {
                                type: "POST",
                                url: "UKeyApplyHasReview.aspx/deleteNode",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                complete: function (e) {
                                    $("#noteGrid").data("kendoGrid").dataSource.read();
                                }
                            },
                            create: {
                                type: "POST",
                                url: "UKeyApplyHasReview.aspx/createNode",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                complete: function (e) {
                                    $("#noteGrid").data("kendoGrid").dataSource.read();
                                }
                            },
                            parameterMap: function (options, operation) {

                                if (operation == "read") {
                                    return "{buildCode:'" + $('#txtBuildCode').val() + "',buildName:'" + $('#txtBuildName').val() + "',nodeId:'" + $('#txtNodeID').val() + "',city:'" + $('#<%=cityname.ClientID %>').val() + "',buildingFuncName:'" + $('#funcname').val() + "',ManufacturerName:'" + $('#<%=applyunit.ClientID %>').val() + "',ISReceive:'" + $('#ddlReceive').val() + "',pageSize:'" + options.pageSize + "',pageIndex:'" + options.page + "'}";
                                }
                                if (operation == "update") {
                                    return "{State:'" + options.State +
                                    "',ManufacturersName:'" + options.ManufacturersName +
                                    "',Remark:'" + options.Remark +
                                    "',BuildAddress:'" + options.BuildAddress +
                                    "',Owners:'" + options.Owners +
                                    "',BuildArea:'" + options.BuildArea +
                                    "',MailAddress:'" + options.MailAddress +
                                    "',consignee:'" + options.consignee +
                                    "',ContactWay:'" + options.ContactWay +
                                     "',IsAOrBInfo:'" + options.IsAOrBInfo.IsAOrBWayValue +
                                    "',NodeID:'" + options.NID +
                                    "'}";
                                }
                                if (operation == "destroy") {
                                    return "{NodeID:'" + options.NID +
                                    "'}";
                                }
                                if (operation == "create") {
                                    return "{BuildingFunc:'" + options.BuildingFuncInfo +
                                    "',NodeName:'" + options.NodeName +
                                    "',BuildAddress:'" + options.BuildAddress +
                                    "',Owners:'" + options.Owners +
                                    "',BuildArea:'" + options.BuildArea +
                                    "',MailAddress:'" + options.MailAddress +
                                    "',consignee:'" + options.consignee +
                                    "',ContactWay:'" + options.ContactWay +
                                     "',IsAOrBInfo:'" + options.IsAOrBInfo +
                                    "',CityID:'" + options.areainfo +
                                    "',State:'" + options.State +
                                    "',ManufacturerName:'" + options.ManufacturersName +
                                      "',Remark:'" + options.Remark +
                                    "'}";
                                }
                            }
                        },
                        pageSize: 13,
                        serverPaging: true,
                        schema: {
                            model: {
                                fields: {
                                    NID: { type: "int", editable: false, nullable: true },
                                    NodeID: { type: "string", editable: false, nullable: true },
                                    NodeName: { type: "string", validation: { required: true} },
                                    areainfo: {},
                                    BuildingFuncInfo: {},
                                    State: { type: "boolean" },
                                    ManufacturersName: { type: "string", validation: { required: true} },
                                    BuildAddress: { type: "string", validation: { required: true} },
                                    Owners: { type: "string", validation: { required: true} },
                                    BuildArea: { type: "float", validation: { required: true} },
                                    MailAddress: { type: "string", validation: { required: true} },
                                    consignee: { type: "string", validation: { required: true} },
                                    ContactWay: { type: "string", validation: { required: true} },
                                    IsAOrBInfo: {},
                                    CreateTime: { editable: false, type: "date" },
                                    Remark: { type: "string" }
                                },
                                id: "NID"
                            },
                            data: "DataList",
                            total: "Count",
                            parse: function (data) {
                                return jQuery.parseJSON(data.d);
                            }
                        }
                    },
                    pageable: true,
                    detailTemplate: kendo.template($("#template").html()),
                    detailInit: detailInits,
                    scrollable: false,

                    columns: [
                    {
                        field: "NID",
                        width: 60,
                        title: "编号"
                    },
                    {
                        field: "NodeID",
                        title: "节点编号"
                    },
                    {
                        field: "NodeName",
                        title: "节点名称",
                        width: 100
                    },
                    {
                        field: "areainfo",
                        title: "所属地市",
                        width: 100,
                        editor: function (container, options) {
                            // create a KendoUI AutoComplete widget as column editor
                            $('<input name="CityName" data-text-field="CityName" data-value-field="CityID" data-bind="value:' + options.field + '"  required="required"/>')
                                .appendTo(container)
                                .kendoComboBox({
                                    dataTextField: "CityName",
                                    dataValueField: "CityID",
                                    dataSource: categories,
                                    filter: "contains",
                                    suggest: true,
                                    optionLabel: "请选择"
                                });
                            $('$<span class="k-invalid-msg" data-for="CityName"></span>').appendTo(container);
                        },
                        template: "#=areainfo.CityName#"
                    },
                    {
                        field: "BuildingFuncInfo",
                        title: "建筑功能",
                        width: 100,
                        editor: function (container, options) {
                            $('<input name="BuildingFuncName" data-text-field="BuildingFuncName" data-value-field="BuildingFunc" data-bind="value:' + options.field + '" required="required"/>')
                                .appendTo(container)
                                .kendoDropDownList({
                                    dataTextField: "BuildingFuncName",
                                    dataValueField: "BuildingFunc",
                                    dataSource: categoriesFunc,
                                    filter: "contains",
                                    suggest: true,
                                    optionLabel: "请选择"
                                });
                            $('$<span class="k-invalid-msg" data-for="BuildingFuncName"></span>').appendTo(container);
                        },
                        template: "#=BuildingFuncInfo.BuildingFuncName#"
                    },
                    {
                        field: "State",
                        template: "#= State ? '是' : '否'#",
                        title: "是否领取"
                    },
                    {
                        field: "ManufacturersName",
                        title: "厂家名称",
                        width: 100
                    },
                     {
                         field: "BuildAddress",
                         title: "建筑地址",
                         width: 100
                     },
                      {
                          field: "Owners",
                          title: "业主",
                          width: 100
                      },
                       {
                           field: "BuildArea",
                           title: "建筑面积",
                           width: 100
                       },
                        {
                            field: "MailAddress",
                            title: "邮寄地址",
                            width: 100
                        },
                         {
                             field: "consignee",
                             title: "收件人",
                             width: 100
                         },
                          {
                              field: "ContactWay",
                              title: "联系方式",
                              width: 80
                          },
                           {
                                field: "IsAOrBInfo",
                               title: "甲方或乙方",
                               width: 80,
                               editor: function (container, options) {
                                   $('<input name="IsAOrBWay" data-text-field="IsAOrBWay" data-value-field="IsAOrBWayValue" data-bind="value:' + options.field + '" required="required"/>')
                                .appendTo(container)
                                .kendoDropDownList({
                                    dataTextField: "IsAOrBWay",
                                    dataValueField: "IsAOrBWayValue",
                                    dataSource: partData,
                                    filter: "contains",
                                    suggest: true,
                                    optionLabel: "请选择"
                                });
                                   $('$<span class="k-invalid-msg" data-for="IsAOrBWay"></span>').appendTo(container);
                               },
                               template: "#=IsAOrBInfo.IsAOrBWay#"


                           },


                    {
                        field: "CreateTime",
                        title: "制作时间",
                        format: "{0:yyyy-MM-dd HH:mm}",
                        width: 100
                    },
                    {
                        field: "Remark",
                        title: "备注",
                        width: 10
                    }

//                    {
//                        title: "&nbsp;", width: "100px",
//                        command: [{ name: "edit", text: "修改" }, { name: "destroy", text: "删除"}],
//                        hidden:true

//                    },

                ],
//                    toolbar: [{ name: "create", text: "添加"}],
//                    editable: "inline"
                });

                var grid = $("#noteGrid").data("kendoGrid");

            }

            function bindBuildingFunc() {
                $.ajax({
                    type: "POST",
                    url: "UKeyApplyHasReview.aspx/LoadBuildFunc2",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        $("#ddlBuildingFunc").kendoDropDownList({
                            dataTextField: "BuildingFuncName",
                            dataValueField: "BuildingFunc",
                            dataSource: jQuery.parseJSON(msg.d),
                            index: 0,
                            change: function () {
                                $("#funcname").val(this.value());
                            }
                        });
                    }
                });
            }
        });




        function detailInits(e) {

            var detailRow = e.detailRow;

            sellectedNodeID = e.data.NID;
            sellectedBuildingFunc = e.data.BuildingFuncInfo.BuildingFunc; //选择的建筑类型
            sellectedCityID = e.data.areainfo.CityID; //选择的城市
            //            sellectedAorB = e.data.IsAOrBInfo.IsAOrBWayValue; //选择的甲方还是乙方

            detailRow.find(".buildingTab").kendoTabStrip({
                animation: {
                    open: { effects: "fadeIn" }
                }
            });

            var buildingGrid = detailRow.find(".buildingGrid").kendoGrid({
                dataSource: {
                    transport: {
                        dataType: "json",
                        read: {
                            type: "POST",
                            url: "UKeyApplyHasReview.aspx/LoadBuildingList",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        update: {
                            type: "POST",
                            url: "UKeyApplyHasReview.aspx/updateBuilding",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        destroy: {
                            type: "POST",
                            url: "UKeyApplyHasReview.aspx/deleteBuilding",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        create: {
                            type: "POST",
                            url: "UKeyApplyHasReview.aspx/createBuilding",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            complete: function (e) {
                                $(".buildingGrid").data("kendoGrid").dataSource.read();
                            }
                        },
                        parameterMap: function (options, operation) {
                            if (operation == "read") {
                                return "{sellectedNodeID:'" + sellectedNodeID +
                                "'}";
                            }
                            if (operation == "update") {
                                return "{CityID:'" + sellectedCityID +
                                "',BuildingFunc:'" + sellectedBuildingFunc +
                                "',SerialNumber:'" + options.SerialNumber +
                                "',BuildingName:'" + options.BuildingName +
                                "'}";
                            }
                            if (operation == "destroy") {
                                return "{CityID:'" + sellectedCityID +
                                "',BuildingFunc:'" + sellectedBuildingFunc +
                                "',SerialNumber:'" + options.SerialNumber +
                                "'}";
                            }
                            if (operation == "create") {
                                return "{BuildingName:'" + options.BuildingName +
                                "',BuildingFunc:'" + sellectedBuildingFunc +
                                "',CityID:'" + sellectedCityID +
                                "',NodeID:'" + sellectedNodeID +
                                "'}";
                            }
                        }
                    },
                    schema: {
                        model: {
                            fields: {
                                BID: { type: "int", editable: false, nullable: true },
                                BuildingID: { type: "string", editable: false, nullable: true },
                                BuildingName: { type: "string", validation: { required: true} }
                            },
                            id: "BID"
                        },
                        data: "DataList",
                        total: "Count",
                        parse: function (data) {
                            return jQuery.parseJSON(data.d);
                        }
                    }
                },

                scrollable: false,
                columns: [
                   { field: "BID", title: "编号", width: 50 },
                   { field: "BuildingID", title: "建筑编号", width: 50 },
                   { field: "BuildingName", title: "建筑名称", width: 50 }
//                   { command: [{ name: "edit", text: "修改" }, { name: "destroy", text: "删除"}], title: "&nbsp;", width: "210px" }
                ],
//                toolbar: [{ name: "create", text: "添加"}],
                editable: "inline"
            });
        }
    </script>
    <style type="text/css">
        .employee-details ul
        {
            list-style: none;
            font-style: italic;
            margin-bottom: 20px;
        }
        
        .employee-details label
        {
            width: 90px;
            font-style: normal;
            font-weight: bold;
        }
    </style>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="Server">
    <%--<div class="nav_title">
        <a href="../Home/Default.aspx"><font color="#0088CC">首页</font></a> >> Ukey管理 </div>--%>
    <div class="ContentMain">
        <div style="width: 1155px; margin: 10px auto;">
            <div>
                <table cellpadding="0" cellspacing="0" border="0" style="width: 80%; margin: 0px auto;">
                    <tr>
                        <td>
                            节点编号:
                        </td>
                        <td>
                            <input type="text" id="txtNodeID" name="txtNodeID" />
                        </td>
                        <td>
                            是否领取
                        </td>
                        <td>
                            <select id="ddlReceive" name="ddlReceive" style="width: 50px">
                                <option value="">全部</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </td>
                        <td>
                            建筑功能:
                        </td>
                        <td>
                            <select id="ddlBuildingFunc" name="ddlBuildingFunc">
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            建筑编码:
                        </td>
                        <td>
                            <input type="text" id="txtBuildCode" name="txtBuildCode" />
                        </td>
                        <td>
                            建筑名称:
                        </td>
                        <td>
                            <input type="text" id="txtBuildName" name="txtBuildName" />
                        </td>
                        <td>
                            <input type="button" id="btnSelect" value="查询" />
                        </td>
                        <td>
                            <asp:Button ID="btnExportExcel" runat="server" Text="导出Excel" OnClick="btnExportExcel_Click" />
                        </td>
                    </tr>
                </table>
            </div>
            <div id="example" class="k-content">
                <div id="noteGrid" style="width: 1155px; margin: 10px auto">
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" id="funcname" /><!--建筑功能-->
    <input type="hidden" id="cityname" runat="server" />
    <!--所属地市-->
    <input type="hidden" id="applyunit" runat="server" />
    <!--厂家-->
</asp:Content>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值