Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net的jqgrid中的每一行中添加按钮_C#_Jquery_Asp.net_Jqgrid - Fatal编程技术网

C# 如何在asp.net的jqgrid中的每一行中添加按钮

C# 如何在asp.net的jqgrid中的每一行中添加按钮,c#,jquery,asp.net,jqgrid,C#,Jquery,Asp.net,Jqgrid,Jqgrid对我来说是新的。所以请帮助我。我的代码如下,但我想在每行中添加一个编辑按钮。请给我答案,当我单击编辑按钮时,它会转到下一页,并通过查询字符串选择id <body> <table style="border: solid 15px red; width: 100%; vertical-align: central;"> <tr> <td style="padding-left: 20px; p

Jqgrid对我来说是新的。所以请帮助我。我的代码如下,但我想在每行中添加一个编辑按钮。请给我答案,当我单击编辑按钮时,它会转到下一页,并通过查询字符串选择id

<body>

    <table style="border: solid 15px red; width: 100%; vertical-align: central;">

        <tr>
            <td style="padding-left: 20px; padding-top: 20px; padding-bottom: 20px; background-color: skyblue; font-family: 'Times New Roman'; font-weight: bold; font-size: 20pt; color: chocolate;">jQ Grid Example In  ASP.NET C#
            </td>
        </tr>
        <tr>
            <td style="text-align: center; vertical-align: central; padding: 50px;">
                <table id="dataGrid" style="text-align: center;">
                </table>
                <div id="pagingGrid"></div>
            </td>
        </tr>
    </table>

</body>

<script type="text/javascript">

    $(function () {
        debugger;
        $("#dataGrid").jqGrid({
            url: 'CityGrid.aspx/GetDataFromDB',
            datatype: 'json',
            mtype: 'POST',

            serializeGridData: function (postData) {
                return JSON.stringify(postData);
            },

            ajaxGridOptions: { contentType: "application/json" },
            loadonce: true,
            colNames: ['CityId', 'CityName'],
            colModel: [

                            { name: 'CityId', index: 'CityId', width: 140 },
                            { name: 'CityName', index: 'CityName', width: 160 },

            ],
            pager: '#pagingGrid',
            rowNum: 5,
            rowList: [10, 20, 30],
            viewrecords: true,
            gridview: true,
            jsonReader: {
                page: function (obj) { return 1; },
                total: function (obj) { return 1; },
                records: function (obj) { return obj.d.length; },
                root: function (obj) { return obj.d; },
                repeatitems: false,
                id: "0"
            },
            caption: 'jQ Grid Example'
        });
    });
</script>


ASP.NETC中的jQ网格示例#
$(函数(){
调试器;
$(“#数据网格”).jqGrid({
url:'CityGrid.aspx/GetDataFromDB',
数据类型:“json”,
mtype:“POST”,
serializeGridData:函数(postData){
返回JSON.stringify(postData);
},
ajaxGridOptions:{contentType:“application/json”},
有一次:是的,
colNames:['CityId','CityName'],
colModel:[
{name:'CityId',index:'CityId',宽度:140},
{name:'CityName',index:'CityName',宽度:160},
],
寻呼机:“#分页网格”,
行数:5,
行列表:[10,20,30],
viewrecords:是的,
gridview:没错,
jsonReader:{
第页:函数(obj){return 1;},
总计:函数(obj){return 1;},
记录:函数(obj){return obj.d.length;},
根:函数(obj){return obj.d;},
重复项:false,
id:“0”
},
标题:“jQ网格示例”
});
});
试试这个。 将colModel更改为如下所示:

colModel: [
    { name: 'CityId', index: 'CityId', width: 140},
    { name: 'CityName', index: 'CityName', width: 160 },
    { name: 'action', index: 'action', width: 75, sortable: false, jsonmap: "CityId",
        formatter:function (cellvalue, options, rowObject) {    
            return "<input type='button' value='somevalue' onclick='some_function'\>";
        }
    }
],
colModel:[
{name:'CityId',index:'CityId',宽度:140},
{name:'CityName',index:'CityName',宽度:160},
{name:'action',index:'action',width:75,sortable:false,jsonmap:'CityId',
格式化程序:函数(cellvalue、options、rowObject){
返回“”;
}
}
],
使用完整代码更新:

<!--
    1) On Double click - Edit the row
    2) On select (checking checkbox) - Edit the row
    3) On click of Select All (multiselect checkbox) - Edit  All rows
    4) Sorting of ALL columns at any time (that means even if one or more row(s) is/are in edit mode, sorting should work for all columns with edit value )
    5) 
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>http://stackoverflow.com/a/20165553/315935</title>
    <meta name="author" content="Oleg Kiriljuk">
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/jquery-ui.css">
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://rawgit.com/free-jqgrid/jqGrid/master/css/ui.jqgrid.css">
    <style>
        html, body { font-size: 75%; }
        .frozen-bdiv {
            top: 83px !important;
        }

        .ui-datepicker select.ui-datepicker-year,
        .ui-datepicker select.ui-datepicker-month {
            color: black
        }
        .ui-jqgrid >.ui-jqgrid-pager .navtable,
        .ui-jqgrid >.ui-jqgrid-view > .ui-jqgrid-toppager .navtable {
            font-size: 16px;
        }
        .ui-pg-table .ui-pg-button:hover {
            border: 0 none;
            background: #b6dbf7 url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png") 50% 50% repeat-x;
        }
        .ui-pg-table .ui-pg-table .ui-pg-button:hover {
            font-weight: normal;
            padding: 0;
            margin: 3px;
        }
        .ui-jqgrid .ui-pg-table.navtable .ui-pg-button:hover {
            font-weight: normal;
            padding: 0;
            margin: 2px;
        }
        .ui-jqgrid .jqgrow  .ui-jqgrid-actions > .ui-pg-div:hover {
            margin: 0 1px;
            border: 0 none;
            background: #b6dbf7 url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png") 50% 50% repeat-x;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.js"></script>
    <!--<script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/i18n/grid.locale-en.js"></script>-->
    <script>
        $.jgrid = $.jgrid || {};
        $.jgrid.no_legacy_api = true;
        $.jgrid.useJSON = true;
    </script>
    <!--<script src="../jqGrid/js/jquery.jqGrid.src.js"></script>-->
    <script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js"></script>
    <!--<script src="http://www.ok-soft-gmbh.com/jqGrid/OK/plugins/jQuery.jqGrid.fontAwesome4.js"></script>
    <script src="http://www.ok-soft-gmbh.com/jqGrid/OK/plugins/jQuery.jqGrid.checkboxFontAwesome4.js"></script>-->
    <script>
        function some_function(clientName) {
            alert("..." + clientName);
        }

    //<![CDATA[
        /*global $ */
        /*jslint browser: true */
        $(function () {
            "use strict";
            var mydata = [
                    { id: "10",  invdate: "2007-10-01", name: "test",   note: "note",   amount: "", tax: "", closed: true,  ship_via: "TN", total: "" },
                    { id: "20",  invdate: "2007-10-02", name: "test2",  note: "note2",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "30",  invdate: "2007-09-01", name: "test3",  note: "note3",  amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                    { id: "40",  invdate: "2007-10-04", name: "test4 test4 test4",  note: "note4",  amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
                    { id: "50",  invdate: "2007-10-31", name: "test5",  note: "note5",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "60",  invdate: "2007-09-06", name: "test6",  note: "note6",  amount: "400.00", tax: "30.00", closed: false, ship_via: "FE", total: "430.00" },
                    { id: "70",  invdate: "2007-10-04", name: "test7",  note: "note7",  amount: "200.00", tax: "10.00", closed: true,  ship_via: "TN", total: "210.00" },
                    { id: "80",  invdate: "2007-10-03", name: "test8",  note: "note8",  amount: "300.00", tax: "20.00", closed: false, ship_via: "FE", total: "320.00" },
                    { id: "90",  invdate: "2007-09-01", name: "test9 test9 test9 test9 test9",  note: "note9",  amount: "400.00", tax: "30.00", closed: false, ship_via: "TN", total: "430.00" },
                    { id: "100", invdate: "2007-09-08", name: "test10", note: "note10", amount: "500.00", tax: "30.00", closed: true,  ship_via: "TN", total: "530.00" },
                    { id: "110", invdate: "2007-09-08", name: "test11", note: "note11", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" },
                    { id: "120", invdate: "2007-09-10", name: "test12", note: "note12", amount: "500.00", tax: "30.00", closed: false, ship_via: "FE", total: "530.00" }
                ],
                $grid = $("#list"),
                initDateEdit = function (elem) {
                    $(elem).datepicker({
                        dateFormat: "dd-M-yy",
                        autoSize: true,
                        changeYear: true,
                        changeMonth: true,
                        showButtonPanel: true,
                        showWeek: true
                    });
                },
                initDateSearch = function (elem) {
                    setTimeout(function () {
                        $(elem).datepicker({
                            dateFormat: "dd-M-yy",
                            autoSize: true,
                            changeYear: true,
                            changeMonth: true,
                            showWeek: true,
                            showButtonPanel: true
                        });
                    }, 100);
                },
                integerTemplate = {formatter: "integer", align: "right", sorttype: "integer",
                    editrules: {number: true, required: true},
                    searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }},
                numberTemplate = {formatter: "number", align: "right", sorttype: "number",
                    editrules: {number: true, required: true},
                    searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }};

            $.extend(true, $.jgrid.icons, {
                common: "fa fa-lg"
            });

            $grid.jqGrid({
                data: mydata,
                colNames: ["", "Client", "Date", "Amount", "Tax", "Total", "Closed", "Shipped via", "Notes", "action"],
                colModel: [
                    { name: "act", template: "actions", width: 60 },
                    { name: "name", align: "center", width: 65, frozen: true, editrules: {required: true} },
                    { name: "invdate", width: 80, align: "center", sorttype: "date", 
                        formatter: "date", formatoptions: { newformat: "d-M-Y", reformatAfterEdit: true }, datefmt: "d-M-Y",
                        editoptions: { dataInit: initDateEdit },
                        searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"], dataInit: initDateSearch } },
                    { name: "amount", width: 200, template: "number" },
                    { name: "tax", width: 52, template: "number", autoResizableMinColSize: 40 },
                    { name: "total", width: 60, template: "number" },
                    {name: "closed", width: 70, align: "center", formatter: "checkboxFontAwesome4", //formatter: "checkbox",
                        edittype: "checkbox", editoptions: {value: "Yes:No", defaultValue: "Yes"},
                        stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;true:Yes;false:No" } },
                    {name: "ship_via", width: 105, align: "center", formatter: "select",
                        edittype: "select", editoptions: { value: "FE:FedEx;TN:TNT;IN:Intim", defaultValue: "IN" },
                        stype: "select", searchoptions: { sopt: ["eq", "ne"], value: ":Any;FE:FedEx;TN:TNT;IN:IN" } },
                    { name: "note", width: 60, edittype: "textarea" },
                    { name: 'action', index: 'action', width: 75, sortable: false, jsonmap: "name",
                        formatter:function (cellvalue, options, rowObject) {    
                            return "<input type='button' value='Details' onclick='some_function(\""+cellvalue+"\")'\>";
                        }
                    }
                ],
                cmTemplate: { editable: true, autoResizable: true },
                rowNum: 100,
                autoResizing: { compact: true },
                resizeStop: function () {
                    var newWidth = this.grid.newWidth, maxIterations = 3, i;
                    for (i = 0; i < maxIterations; i++) {
                        // resize without shrinking
                        $(this).jqGrid("setGridWidth", newWidth + i, false);
                        if (this.grid.bDiv.offsetHeight <= this.grid.bDiv.clientHeight) {
                            break;
                        }
                    }
                },
              //  rowList: [5, 10, 20],
                pager: "#pager", // "#pa\\.ger" or "pa.ger"
                pgtext : "",
                pginput: false,
                pgbuttons: false,
                viewrecords: true,
                gridview: true,
                iconSet: "fontAwesome",
                toppager: false,
                bottompager: false,
                toolbar: [false, "both"],
                footerrow: false,
                multiselect: true,
                rownumbers: false,
                //direction: "rtl",
                //recordpos: "left",
                //cellEdit: true,
                //beforeSaveCell: function (rowid, name, value, iRow, iCol) {
                //    var cm = this.p.colModel[iCol];
                //    return cm.formatter !== "date" ? value : $.unformat.date.call(this, value, cm);
                //},
                sortname: "invdate",
                sortorder: "desc",
                resizeDblClick: function (iCol, cm) {
                    //alert("DblClick on the column resizer of the column \"" + cm.name + "\"");
                    //autoResizeColumn.call(this, iCol);
                },
                ondblClickRow: function(id){
                    $grid.jqGrid("setSelection", id);  // Select the row on Double Click
                    $grid.jqGrid('editRow', id, true); // Edit the row on Double Click
                },
                onSelectRow: function (rowid, stat, e) {
                    return;
                },
                inlineEdit: {
                    keys: true
                },
                //viewsortcols: [true, "horizontal", false], // [true, "vertical", false] or [true, "vertical", false]
                //subGrid: true,
                subGridRowExpanded: function (subgridDivId, rowId) {
                    $("#" + $.jgrid.jqID(subgridDivId)).html("<em>simple subgrid data for the row with id=" + rowId + "</em>");
                },
                caption: "Demonstration of the usage sortable:true and frozen formatter: \"actions\"",
                width: 500,
                height: 200,
                sortable: true,
                //height: 100,
                shrinkToFit: false,
                autoresizeOnLoad: true
            });
            //$grid.jqGrid("setFrozenColumns");
            //$grid.jqGrid("navGrid", "#pager", {view: true, cloneToTop: true/*, position: "right"*/})
            $grid.jqGrid("navGrid", "#pager", { resize: false, add: false, search: false, del: false, refresh: false, edit: false,    alerttext: 'Please select one user' })
            .jqGrid("inlineNav", "#list_toppager")
           // .jqGrid("inlineNav", "#pager")
            .jqGrid("filterToolbar");
            //$grid.jqGrid("destroyFrozenColumns");
            $grid.jqGrid("setFrozenColumns");
            //$grid.trigger("jqGridResetFrozenHeights");
            //$.jgrid.info_dialog($.jgrid.errors.errcap, "Test message", $.jgrid.edit.bClose);
            //$grid.jqGrid("sortableRows");
            //$("#outerDiv").show();
            //$grid.jqGrid("autoResizeAllColumns");
            $grid.jqGrid("gridResize"); // , {handles: "e, w", shrinkToFit: false}
            //var allData = $grid.jqGrid("getRowData");

            $(window).on("resize", function() {
                $("table.ui-jqgrid-btable").each(function () {
                    $(this).trigger("jqGridResetFrozenHeights");
                });
            });

            // Custom row to do Mass Edit
            var t1 = '<div style="POSITION: absolute; TOP: 56px; left: -2px;"><table><tr id="massEditFrizenTR" >'
                    +'  <th style= "width: 21px; text-align: left; vertical-align: top; padding-left: 0px !important;" class="noBoderTD"> </th> '
                    +'  <th style= "width: 60px;"> &nbsp; </th><th width="136" class="massEditClient"> &nbsp; </th>'
                    +'  <th width="68" class="massEditDate"> &nbsp; </th>';
            var t2 = '<tr id="massEditTR" > '
                    +'  <th style= "width: 21px; text-align: left; vertical-align: top; padding-left: 0px !important;" class="noBoderTD"> </th> '
                    +'  <th style= "width: 60px;"> &nbsp; </th>'
                    +'  <th width="136" class="massEditClient"> &nbsp; </th>'
                    +'  <th width="68" class="massEditDate">  </th>'
                    +'  <th width="52" class="massEditAmount ui-search-input"> <SELECT id="massEditAmoutSelect" name="massEditAmoutSelect" style="width: 11;"><OPTION value="Select">Select</OPTION><OPTION value="High">100</OPTION><OPTION value="Medium">200</OPTION><OPTION value="Low">300</OPTION></SELECT></th>'
                    +'  <th width="33" class="massEditTax"> &nbsp; </th>'
                    +'  <th width="38" style="" class="massEditTotal"> &nbsp; </th>'
                    +'  <th width="47" style=""  class="massEditClosed"> &nbsp; </th>'
                    +'  <th width="72" style=""  class="massEditShippedVia"> &nbsp; </th> '
                    +'  <th width="41" style="" class="massEditNotes"> &nbsp; </th></tr>';
            if ($('#massEditTR').length){
            } else {
                $(".ui-search-toolbar").after(t2);
            //  $(".ui-jqgrid-hdiv:first").after(t1);
            }

        });
    //]]>
    </script>
</head>
<body>
    <div id="outerDiv" style="margin:5px;">
        <table id="list"></table>
        <div id="pager"></div>
    </div>
</body>
</html>

http://stackoverflow.com/a/20165553/315935
html,正文{字体大小:75%;}
.冷冻bdiv{
顶部:83px!重要;
}
.ui日期选择器select.ui-datepicker-year,
.ui日期选择器select.ui-datepicker-month{
颜色:黑色
}
.ui jqgrid>.ui jqgrid pager.navtable,
.ui jqgrid>.ui jqgrid视图>.ui jqgrid TopPage.navtable{
字体大小:16px;
}
.ui pg table.ui pg按钮:悬停{
边界:0无;
背景:#b6dbf7 url(“https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png)50%50%重复-x;
}
.ui pg table.ui pg table.ui pg按钮:悬停{
字体大小:正常;
填充:0;
保证金:3倍;
}
.ui jqgrid.ui-pg-table.navtable.ui pg按钮:悬停{
字体大小:正常;
填充:0;
保证金:2倍;
}
.ui jqgrid.jqgrow.ui jqgrid actions>.ui pg div:hover{
利润率:0.1px;
边界:0无;
背景:#b6dbf7 url(“https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png)50%50%重复-x;
}
$.jgrid=$.jgrid | |{};
$.jgrid.no_legacy_api=true;
$.jgrid.useJSON=true;
函数some_函数(clientName){
警报(“…”+客户端名称);
}
//

试试这个谢谢先生的回复并给我时间谢谢先生但很抱歉,这个代码不起作用。请给我新的想法。再次感谢您的回复并给我时间谢谢先生这个代码工作得很好。再次感谢您的帮助。@ParthaPriyadarshi:您介意点击勾号接受答案吗投票结果如何?