Hello,
I'm having an issue with a radgrid that populates data from a linq query. The grid uses an OnItemDataBound and OnItemCommand method.
Looking at the page source after being compiled, the viewstate looks absolutely massive, as if the grid is trying to stick the binary file in the viewstate somehow.
I tried increasing the size of the maxJsonLength through web.config to no avail.
The specific error is:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
I'm uploading a file, and then clicking back to a page that rebinds the radgrid containing an attachment column which triggers the onitemcommand method.
Thanks ahead of time.
ASPX:
CS:
I'm having an issue with a radgrid that populates data from a linq query. The grid uses an OnItemDataBound and OnItemCommand method.
Looking at the page source after being compiled, the viewstate looks absolutely massive, as if the grid is trying to stick the binary file in the viewstate somehow.
I tried increasing the size of the maxJsonLength through web.config to no avail.
The specific error is:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
I'm uploading a file, and then clicking back to a page that rebinds the radgrid containing an attachment column which triggers the onitemcommand method.
Thanks ahead of time.
ASPX:
<
telerik:RadGrid
ID
=
"procGrid"
runat
=
"server"
AutoGenerateColumns
=
"False"
CellSpacing
=
"0"
GridLines
=
"None"
onneeddatasource
=
"procGrid_NeedDataSource"
OnItemDataBound
=
"grdProcedures_ItemDataBound2"
OnItemCommand
=
"grdFiles_ItemCommand"
>
<
MasterTableView
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
Visible
=
"True"
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"True"
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"Filter column column"
UniqueName
=
"column"
DataField
=
"name"
HeaderText
=
"Name"
>
<
ItemStyle
Width
=
"400px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Id"
FilterControlAltText
=
"Filter column1 column"
UniqueName
=
"column1"
>
</
telerik:GridBoundColumn
>
<
telerik:GridHyperLinkColumn
AllowSorting
=
"False"
FilterControlAltText
=
"Filter column2 column"
UniqueName
=
"column2"
HeaderText
=
"Review"
>
<
ItemStyle
Width
=
"100px"
/>
</
telerik:GridHyperLinkColumn
>
<
telerik:GridAttachmentColumn
FileName
=
"attachment"
FilterControlAltText
=
"Filter procedure_document column"
HeaderText
=
"Procedures"
UniqueName
=
"procedure_document"
AttachmentDataField
=
"procedure_document"
AttachmentKeyFields
=
"procedure_document"
Text
=
"View Procedure"
>
</
telerik:GridAttachmentColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
<
ClientSettings
EnablePostBackOnRowClick
=
"true"
>
</
ClientSettings
>
</
telerik:RadGrid
>
CS:
protected void grdProcedures_ItemDataBound2(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
string ProcId = item["column1"].Text;
HyperLink link = (HyperLink)item["column2"].Controls[0];
link.Text = "Edit Procedure";
string url = "~/procedure.aspx?AuditType=" + AuditType + "&AuditID=" + AuditID + "&StandardID=" + StandardID + "&ProcedureID=" + ProcId;
link.NavigateUrl = url;
}
}
protected void grdFiles_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
{
using (var db = new isoAuditModelContainer())
{
RadAjaxManager Manager = new RadAjaxManager();
Manager.EnableAJAX = false;
GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
GridDataItem item = (GridDataItem)e.Item;
string fileName = args.FileName;
string ProcId = item["column1"].Text;
int ProcId2 = Convert.ToInt16(ProcId);
//int attachmentId = (int)args.AttachmentKeyValues["procedure_document"];
var query = (from x in db.procedures where x.Id == ProcId2 select x).First();
string extension = query.file_extension;
byte[] binaryData = (byte[])query.procedure_document;
Response.Clear();
//Response.ContentType = query.fileExtension;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + extension);
Response.BinaryWrite(binaryData);
Response.OutputStream.Write(binaryData, 0, binaryData.Length);
Response.Flush();
Response.Close();
Response.End();
}
}
}