jqGrid查询RowNumber错误

时间:2010-02-16 08:18:05

标签: jqgrid

我绑定了jqGrid。 我的控制器类包含以下代码。这段代码我从代码中获得,现在它给RowNumber一个错误。为什么,以及如何解决问题?

public ActionResult GetGridData(string sidx, string sord, int page, int rows) {
    return Content(
      JsonHelper.JsonForJqgrid(GetDataTable(sidx,sord,page,rows),
      rows,
      GetTotalCount(),
      page),
      "application/json");
}

public DataTable GetDataTable(string sidx, string sord, int page, int pageSize) {
    int startIndex = (page-1) * pageSize;
    int endIndex = page * pageSize;
    string sql =
        @"WITH PAGED_CUSTOMERS  AS
        (
         SELECT Register_Id,FullName,CompanyName, EmployeeName, RegisterDate,
            ROW_NUMBER() OVER (ORDER BY " + sidx + @" " + sord + @") AS RowNumber
         FROM GP_Register
        )
        SELECT  Register_Id,FullName,CompanyName, EmployeeName, RegisterDate
        FROM GP_Register
        WHERE RowNumber BETWEEN " + startIndex + @" AND " + endIndex + @";";

    DataTable dt = new DataTable();
    SqlConnection conn = new SqlConnection("Data Source=MAXNET016;Initial Catalog=GuestPass;User ID=sa;Password=maxsql");
    conn.Open();
        SqlDataAdapter adap = new SqlDataAdapter(sql,conn);
    var rows=adap.Fill(dt);
    return dt;
}

public int GetTotalCount() {
    string sql = @"SELECT COUNT(*) FROM GP_Register WHERE Register=0";
    SqlConnection conn=null;
    try {
        conn = new SqlConnection("Data Source=MAXNET016;Initial Catalog=GuestPass;User ID=sa;Password=maxsql");
        SqlCommand comm = new SqlCommand(sql, conn);
        conn.Open();
        return (int)comm.ExecuteScalar();
    }
    catch
    {
    }
    finally
    {
        try {
            if (ConnectionState.Closed != conn.State) {
                conn.Close();
            }
        }catch {
        }
    }
    return -1;
  }

在aspx页面中,我采用了jqGrid:

<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery("#list").jqGrid({
            url: '/Home/GetGridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['FullName', 'CompanyName', 'EmployeeName', 'RegisterDate'],
            colModel: [
              { name: 'FullName', index: 'FullName', width: 100, align: 'left'},
              { name: 'CompanyName', index: 'CompanyName', width: 150, align: 'left' },
              { name: 'EmployeeName',
                index: 'EmployeeName',
                width: 250,
                align: 'left',
                sortable: false ,
                editable: true,
                edittype: "textarea",
                editoptions: { rows: "2", cols: "20"} },
             { name: 'RegisterDate',
               index: 'RegisterDate',
               width: 150,
               align: 'left',
               sortable: false,
               editable: true,
               edittype: "text",
               editoptions: { size: 10, maxlength: 15} },

            ],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'Register_Id',
            sortorder: "asc",
            viewrecords: true,
            imgpath: '/scripts/themes/steel/images',
            caption: 'Customer Information'
        }).navGrid(pager, { edit: true, add: true, del: true, refresh: true, search: true });
    });
    jQuery("#list").jqGrid('filterToolbar');

    function checkboxFormatter(el, cval, opts) {
        cval = cval + ""; cval = cval.toLowerCase();
        var bchk = cval.search(/(false|0|no|off|n)/i) < 0 ? " checked=\"checked\"" : "";
        // $(el).html("<input type='checkbox' onclick=\"ajaxSave('" + opts.rowId + "', this);\" " + bchk + " value='" + cval + "' offval='no' />");

        //         var s;
        //         s = ("<select name='sel'>");
        //         cval = 1;
        //         while (cval < 10) {
        //             s = s + ("<option='" + cval + "'>" + cval + "</option>");
        //             cval++;
        //         }
        //         s = s + ("</select>");
        //         $(el).html(s);
        //

        var s;
        s = ("<select name='sel'>")
        cval = 1;

        while (cval < 15) {
            s = s + ("<option ='" + cval + "'>" + cval + "</option>");
            cval++;
        }
        s = s + ("</select>");
        $(el).html(s);
    }
</script>

1 个答案:

答案 0 :(得分:0)

对不起,这个代码太多了,不能熬过这个深夜。

你可能会从this获得一些里程。