hey i am not using MVC pattern. I am only using ASP.net 2.0 C#. I am using jqGrid 3.6 version.
I know that there is one property excelexport which need to be set true and we have to add one custom button and the on click of th开发者_开发知识库at button i have to call jqgrid.excelExport method. but i have to send on complex object to the page how do i send it? I dont want to send the search parameters as query string because my search parameters are going to be too long.
You can create this in the C# code:
protected void btnExcel_Click(object sender, EventArgs e)
{
string codigo;
codigo = hdnHtml.Value;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page pagina = new Page();
HtmlForm form = new HtmlForm();
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Visor.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
pagina.EnableEventValidation = false;
pagina.DesignerInitialize();
pagina.Controls.Add(form);
pagina.RenderControl(htw);
Response.Write(codigo);
Response.End();
}
}
In the code behind you can repeat this.
Add to propiertes of page:
validateRequest="false"
<asp:Button ID="btnExcel" runat="server" Text="Export"
onclick="btnExcel_Click" /> //create a button
<asp:HiddenField ID="hdnHtml" runat="server" /> // create a hiddenField
$('[id$=btnExcel]').hide(); // hide the button with jquery function
function exportXls() {
var tbody = $("#jQGrid_Visor").html();
var thead = $(".ui-jqgrid-htable").html();
var htmlTable = "<table>" + thead + tbody + "</table>";
var strCopy = htmlTable;
$('[id$=hdnHtml]').val(strCopy); // fill the hidden with the table content
$('[id$=btnExcel]').click(); // click button hidden
}
In my case I have a menu with the right button that fires the event exportXls, if you want you can leave with C# not hide the button
var eventsMenu = {
bindings: {
'actualizar': function(rowid) {
//alert('Accion [Actualizar] del elemento ' + t.id);
jQuery('#jQGrid_Visor').setGridParam(rowid).trigger("reloadGrid");
},
**'exportar': function(rowid) {
//alert('Accion [Exportar] del elemento ' + rowid.id);
exportXls();**
},
'full': function(t) {
// alert('Accion [Full Screen] del elemento ' + t.id);
window.open("./frmBrwVisorMantencionFullScreen.aspx?cod_flota=" + $('[id$=hdnCodFlota]').val(), "Full_Screen", "scrollbars=NO,Resizable=NO,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=yes");
},
'paste': function(t) {
alert('Accion [Pegar] del elemento ' + t.id);
},
'delete': function(t) {
alert('Accion [Eliminar] del elemento ' + t.id);
}
}
};
精彩评论