Re: Custom UI

  •  03-13-2009, 9:19 PM

    Re: Custom UI

    Matt
     
    If you do not need show the uploaded list , you should not use UploadAttachments control
     
    Here is a sample to render the custom attachments :
     
    1. <%@ Page Language="VB" %>  
    2. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4.   
    5. <script runat="server">  
    6.     Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)   
    7.         MyBase.OnPreRender(e)   
    8.            
    9.         'hide the default table   
    10.         UploadAttachments1.GetItemsTable().Visible = False  
    11.         DataGrid1.DataSource = UploadAttachments1.Items   
    12.         DataGrid1.DataBind()   
    13.     End Sub   
    14.   
    15.     Protected Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)   
    16.         If e.CommandName = "Download" Then   
    17.             Dim guid As Guid = CType(DataGrid1.DataKeys(e.Item.ItemIndex), Guid)   
    18.             For Each item As AttachmentItem In UploadAttachments1.Items   
    19.                 If item.FileGuid = guid Then   
    20.                     Using str As Stream = item.OpenStream()   
    21.                         Response.AddHeader("Content-Disposition", "attachment; filename=" & item.FileName)   
    22.                         Response.AddHeader("Content-Length", item.FileSize)   
    23.                         Dim buff() As Byte = New Byte(4096) {}   
    24.                         While (True)   
    25.                             Dim rc As Integer = str.Read(buff, 0, buff.Length)   
    26.                             If rc = 0 Then   
    27.                                 Exit While   
    28.                             End If   
    29.                             Response.OutputStream.Write(buff, 0, rc)   
    30.                         End While   
    31.                     End Using   
    32.                 End If   
    33.             Next   
    34.         End If   
    35.     End Sub   
    36. </script>  
    37.   
    38. <html xmlns="http://www.w3.org/1999/xhtml">  
    39. <head runat="server">  
    40.     <title>DataGridVB</title>  
    41. </head>  
    42. <body>  
    43.     <form id="form1" runat="server">  
    44.         <div>  
    45.                
    46.             <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" UploadType=Flash>  
    47.             </CuteWebUI:UploadAttachments>  
    48.             <hr />  
    49.             <asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="false"  
    50.  DataKeyField="FileGuid" OnItemCommand="DataGrid1_ItemCommand">  
    51.                 <Columns>  
    52.                     <asp:BoundColumn DataField="FileGuid" HeaderText="File Guid" />  
    53.                     <asp:BoundColumn DataField="FileName" HeaderText="File Name" />  
    54.                     <asp:BoundColumn DataField="FileSize" HeaderText="File Size" />  
    55.                     <asp:ButtonColumn CommandName="Download" Text="Download" />  
    56.                 </Columns>  
    57.             </asp:DataGrid>  
    58.         </div>  
    59.     </form>  
    60.     <script type="text/javascript">  
    61.     var internalobj;   
    62.     var hasprogress=false;   
    63.     function ShowProgress()   
    64.     {   
    65.         if(!internalobj)return;   
    66.         function ShowIt()   
    67.         {   
    68.             internalobj.progressCtrl.style.display="";   
    69.             internalobj.progressText.style.display="";   
    70.             //if(internalobj.progressText.firstChild.nodeName!="TABLE")   
    71.             if(!hasprogress)   
    72.             {   
    73.                 internalobj.progressText.innerHTML=   
    74. "<table border='1' cellspacing=0' cellpadding='1' style='width:360px;border-collapse:collapse;border:1px solid #999999;'>"  
    75. +"<tr><td>Please select a file</td></tr></table>";   
    76.             }   
    77.         }   
    78.         ShowIt();   
    79.         setTimeout(ShowIt,10);   
    80.     }   
    81.     function CuteWebUI_AjaxUploader_OnInitialize()   
    82.     {   
    83.         internalobj=this.internalobject;   
    84.         ShowProgress();   
    85.     }   
    86.     function CuteWebUI_AjaxUploader_OnStart()   
    87.     {   
    88.         ShowProgress();   
    89.     }   
    90.     function CuteWebUI_AjaxUploader_OnStop()   
    91.     {   
    92.         ShowProgress();   
    93.     }   
    94.     function CuteWebUI_AjaxUploader_OnProgress(enabled)   
    95.     {   
    96.         hasprogress=enabled;   
    97.         ShowProgress();   
    98.     }   
    99.     function CuteWebUI_AjaxUploader_OnQueueUI()   
    100.     {   
    101.         ShowProgress();   
    102.     }   
    103.     </script>  
    104. </body>  
    105. </html>  
     
    Regards,
    Terry
     
     
View Complete Thread