开发者

Mvccontrib grid export to excel

I'm using mvccontrib grid to show seach result data and export to excel.

I have found this article for exporting data to excel and implemented successful.

In my solution, My gridview have a checkbox column that support user select number of row that they want to export th开发者_运维问答en export to excel.

Please suggest me solutions how to do this. Thanks in advance


I've already solved my problems. I've used a form tag which post to my Export controller. Inside the form tag I used an hidden field which store my array of ID that I've checked on the grid. Then I called submit the form using javascript to post hidden field string to Export controller. On the controller, I've parsed Id into array then query to get specified my records wanted to export. Below is summary my result.

<%using (Html.BeginForm("Export", "Test", FormMethod.Post, new {id="frmPost" }))
  { %>
    <%=Html.Hidden("cmdListID")%>
    ....
<%} %>

javascript:

$('#cmdExport').click(function () {
            var jsonObj = [];
            var strData = "";
            $('input[name="SelList"]:checked').each(function () {
                jsonObj.push({ key: $(this).attr('id') });
            });

            var postData = { "listID": jsonObj };
            if (jsonObj.length > 0) {
                strData = JSON.stringify(postData);
                $('#cmdListID').val(strData);
            }

            $('#frmPost').submit();
            $('#cmdListID').val('');
        });

Export controller: I created a list object(using serialize json) for parsing my expected list object.

Finally, I queried into database again by filtering using those IDs that I got to receive my expected records. Hope this help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜