Folks
Enviromnent: VS 2010 with RadControls for ASP.NET AJAX Q2 2011 SP1. I am using below link as a prototype for my project.
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/gridattachmentcolumn/defaultcs.aspx
In my project, Download options works if they are not inside edit table. Below declarations works.
<div style="margin-bottom: 5px;"> <telerik:RadComboBox ID="FileNamesComboBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="FileName" DataValueField="ID" CssClass="rgExpXLS"> </telerik:RadComboBox> <asp:LinkButton ID="LinkButton_Dwnload" runat="server" OnClick="DownloadButton_Click" Text="DownLoad"></asp:LinkButton> </div> protected void DownloadButton_Click(object sender, EventArgs e) { int attachmentId = Int32.Parse(FileNamesComboBox1.SelectedValue); string fileName = FileNamesComboBox1.SelectedItem.Text; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString); SqlCommand comm = new SqlCommand("SELECT [BinaryData] FROM [FileData] WHERE [ID] = @ID", conn); comm.Parameters.Add(new SqlParameter("@ID", attachmentId)); SqlDataAdapter adapter = new SqlDataAdapter(comm); DataSet data = new DataSet(); adapter.Fill(data); byte[] binaryData = (byte[])data.Tables[0].Rows[0]["BinaryData"]; int ii = attachmentId; Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + fileName); Response.BinaryWrite(binaryData); Response.End(); }__________________________
But if the download options are within Edit Table, it does not work. Declaration and code:
<EditFormSettings EditFormType="Template"> <FormTemplate> <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse; background: white;"> <tr> <td> <div style="margin-bottom: 5px;"> <telerik:RadComboBox ID="FileNamesComboBox" runat="server" DataSourceID="SqlDataSource1" DataTextField="FileName" DataValueField="ID"> </telerik:RadComboBox> <asp:LinkButton ID="LinkButtonEditTable" runat="server" OnClick="DownloadLinkButtonEditTable_Click" Text="Download from Edit Table" Font-Size="Medium" ForeColor="Red"></asp:LinkButton> </div> </td> </tr> </table> </FormTemplate> </EditFormSettings> protected void DownloadLinkButtonEditTable_Click(object sender, EventArgs e) { LinkButton btn = sender as LinkButton; if (btn.NamingContainer is GridEditableItem ) { // Edit mode GridEditableItem container = (GridEditableItem)btn.NamingContainer; RadComboBox SLurlComboBox = (RadComboBox)container.FindControl("FileNamesComboBox"); int attachmentId = Int32.Parse(SLurlComboBox.SelectedValue); int ii = attachmentId; string fileName = SLurlComboBox.SelectedItem.Text; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString); SqlCommand comm = new SqlCommand("SELECT [BinaryData] FROM [FileData] WHERE [ID] = @ID", conn); comm.Parameters.Add(new SqlParameter("@ID", attachmentId)); SqlDataAdapter adapter = new SqlDataAdapter(comm); DataSet data = new DataSet(); adapter.Fill(data); byte[] binaryData = (byte[])data.Tables[0].Rows[0]["BinaryData"]; Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + fileName); Response.BinaryWrite(binaryData); Response.End(); } }
My project requires download be done within Edit Table. Attached is the error message while trying to download from Edit Table;
Any help will be appreciated. Thanks
gc_0620