putting an an ajax uploader in a repeater

Last post 09-05-2009, 1:57 PM by Lan-Lord. 2 replies.
Sort Posts: Previous Next
  •  08-27-2009, 12:27 PM 55119

    putting an an ajax uploader in a repeater

    Is there some example code that shows how to place an uploader in a repeater (or datagrid, etc) ?
     
    I'm able to put an ajax uploader on the .aspx page, but I'm not sure how to handle the serverside of the upload.
    Thx
     
  •  09-01-2009, 3:49 AM 55230 in reply to 55119

    Re: putting an an ajax uploader in a repeater

    Hi,
     
    Please check this sample code :
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Import Namespace="CuteWebUI" %>  
    4. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    6.   
    7. <script runat="server">  
    8.        
    9.     protected override void OnLoad(EventArgs e)   
    10.     {   
    11.         base.OnLoad(e);   
    12.   
    13.         if (!IsPostBack)   
    14.         {   
    15.             DataTable table = new DataTable();   
    16.             table.Columns.Add("Id", typeof(int));   
    17.             table.Columns.Add("Name", typeof(string));   
    18.             table.Columns.Add("Age", typeof(int));   
    19.             table.AcceptChanges();   
    20.             table.Rows.Add(1, "Sarah", 28);   
    21.             table.Rows.Add(2, "Andy", 32);   
    22.             table.AcceptChanges();   
    23.             table.AcceptChanges();   
    24.             Repeater1.DataSource = table.DefaultView;   
    25.             Repeater1.DataBind();   
    26.         }   
    27.     }   
    28.   
    29.     protected void UploadAttachments1_Init(object sender, EventArgs e)   
    30.     {   
    31.         UploadAttachments uploader = (UploadAttachments)sender;   
    32.   
    33.         uploader.ShowActionButtons = true;   
    34.         uploader.AttachmentActionClicked += new AttachmentItemEventHandler(uploader_AttachmentActionClicked);   
    35.         uploader.ActionButtonBehavior = AttachmentItemBehavior.None;   
    36.         uploader.ActionButtonText = "download";   
    37.     }   
    38.   
    39.     void uploader_AttachmentActionClicked(object sender, AttachmentItemEventArgs args)   
    40.     {   
    41.         UploadAttachments uploader = (UploadAttachments)sender;   
    42.   
    43.         string filepath = args.Item.GetTempFilePath();   
    44.         Response.ContentType = "application/octee-stream";   
    45.         Response.AddHeader("Content-Disposition", "attachment; filename=\"" + args.Item.FileName + "\"");   
    46.         Response.WriteFile(filepath);   
    47.         Response.End();   
    48.     }   
    49.   
    50.     protected void BtnShow_Click(object sender, EventArgs e)   
    51.     {   
    52.         UploadAttachments uploader = (UploadAttachments)FindRepeaterControl(sender, "UploadAttachments1");   
    53.   
    54.         Label1.Text = " BtnShow_Click : There's " + uploader.Items.Count + " file(s)";   
    55.         foreach (AttachmentItem item in uploader.Items)   
    56.         {   
    57.             Label1.Text += "," + HttpUtility.HtmlEncode(item.FileName);   
    58.         }   
    59.     }   
    60.   
    61.     protected Control FindRepeaterControl(object sender, string ctrlid)   
    62.     {   
    63.         RepeaterItem ri = null;   
    64.         for (Control c = (Control)sender; c != null; cc = c.Parent)   
    65.         {   
    66.             ri = c as RepeaterItem;   
    67.             if (ri != null)   
    68.                 break;   
    69.         }   
    70.         if (string.IsNullOrEmpty(ctrlid))   
    71.             return ri;   
    72.         return ri.FindControl(ctrlid);   
    73.     }   
    74.   
    75. </script>  
    76.   
    77. <html xmlns="http://www.w3.org/1999/xhtml">  
    78. <head runat="server">  
    79.     <title>Untitled Page</title>  
    80. </head>  
    81. <body>  
    82.     <form id="form1" runat="server">  
    83.         <div>  
    84.             <asp:Label runat="server" ID="Label1">This is Top!</asp:Label>  
    85.         </div>  
    86.         <asp:Repeater runat="server" ID="Repeater1">  
    87.             <ItemTemplate>  
    88.                 <div style="border: dashed 1px gray; margin: 8px; padding: 12px;">  
    89.                     <div>  
    90.                         Id :   
    91.                         <%# Eval("Id") %>  
    92.                         Name :   
    93.                         <%# Eval("Name") %>  
    94.                         Age :   
    95.                         <%# Eval("Age") %>  
    96.                     </div>  
    97.                     <div>  
    98.                         <asp:LinkButton runat="server" Text="Show me how to get the files" OnClick="BtnShow_Click"  
    99.                             ID="BtnShow" />  
    100.                     </div>  
    101.                     <div>  
    102.                         <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" InsertButtonID="AddFileButton"  
    103.                             OnInit="UploadAttachments1_Init" />  
    104.                         <asp:Label runat="server" ID="AddFileButton">  
    105.                             <asp:Image ID="Image1" runat="server" ImageUrl="http://cutesoft.net/CuteSoft_Client/CuteChat/Images/file.png" />  
    106.                             Add files </asp:Label>  
    107.                     </div>  
    108.                 </div>  
    109.             </ItemTemplate>  
    110.             <SeparatorTemplate>  
    111.                 <hr />  
    112.             </SeparatorTemplate>  
    113.         </asp:Repeater>  
    114.         <div>  
    115.             <asp:Label runat="server" ID="Label2">This is Bottom!</asp:Label>  
    116.         </div>  
    117.     </form>  
    118. </body>  
    119. </html>  
     
    Regards,
    Terry
     
  •  09-05-2009, 1:57 PM 55391 in reply to 55230

    Re: putting an an ajax uploader in a repeater

    Hey thats perfect, thanks for assistance. So far I really like the ajax uploader.
View as RSS news feed in XML