Hi,
Please check this sample code :
- <%@ Page Language="C#" %>
-
- <%@ Import Namespace="CuteWebUI" %>
- <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <script runat="server">
-
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
-
- if (!IsPostBack)
- {
- DataTable table = new DataTable();
- table.Columns.Add("Id", typeof(int));
- table.Columns.Add("Name", typeof(string));
- table.Columns.Add("Age", typeof(int));
- table.AcceptChanges();
- table.Rows.Add(1, "Sarah", 28);
- table.Rows.Add(2, "Andy", 32);
- table.AcceptChanges();
- table.AcceptChanges();
- Repeater1.DataSource = table.DefaultView;
- Repeater1.DataBind();
- }
- }
-
- protected void UploadAttachments1_Init(object sender, EventArgs e)
- {
- UploadAttachments uploader = (UploadAttachments)sender;
-
- uploader.ShowActionButtons = true;
- uploader.AttachmentActionClicked += new AttachmentItemEventHandler(uploader_AttachmentActionClicked);
- uploader.ActionButtonBehavior = AttachmentItemBehavior.None;
- uploader.ActionButtonText = "download";
- }
-
- void uploader_AttachmentActionClicked(object sender, AttachmentItemEventArgs args)
- {
- UploadAttachments uploader = (UploadAttachments)sender;
-
- string filepath = args.Item.GetTempFilePath();
- Response.ContentType = "application/octee-stream";
- Response.AddHeader("Content-Disposition", "attachment; filename=\"" + args.Item.FileName + "\"");
- Response.WriteFile(filepath);
- Response.End();
- }
-
- protected void BtnShow_Click(object sender, EventArgs e)
- {
- UploadAttachments uploader = (UploadAttachments)FindRepeaterControl(sender, "UploadAttachments1");
-
- Label1.Text = " BtnShow_Click : There's " + uploader.Items.Count + " file(s)";
- foreach (AttachmentItem item in uploader.Items)
- {
- Label1.Text += "," + HttpUtility.HtmlEncode(item.FileName);
- }
- }
-
- protected Control FindRepeaterControl(object sender, string ctrlid)
- {
- RepeaterItem ri = null;
- for (Control c = (Control)sender; c != null; cc = c.Parent)
- {
- ri = c as RepeaterItem;
- if (ri != null)
- break;
- }
- if (string.IsNullOrEmpty(ctrlid))
- return ri;
- return ri.FindControl(ctrlid);
- }
-
- </script>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:Label runat="server" ID="Label1">This is Top!</asp:Label>
- </div>
- <asp:Repeater runat="server" ID="Repeater1">
- <ItemTemplate>
- <div style="border: dashed 1px gray; margin: 8px; padding: 12px;">
- <div>
- Id :
- <%# Eval("Id") %>
- Name :
- <%# Eval("Name") %>
- Age :
- <%# Eval("Age") %>
- </div>
- <div>
- <asp:LinkButton runat="server" Text="Show me how to get the files" OnClick="BtnShow_Click"
- ID="BtnShow" />
- </div>
- <div>
- <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" InsertButtonID="AddFileButton"
- OnInit="UploadAttachments1_Init" />
- <asp:Label runat="server" ID="AddFileButton">
- <asp:Image ID="Image1" runat="server" ImageUrl="http://cutesoft.net/CuteSoft_Client/CuteChat/Images/file.png" />
- Add files </asp:Label>
- </div>
- </div>
- </ItemTemplate>
- <SeparatorTemplate>
- <hr />
- </SeparatorTemplate>
- </asp:Repeater>
- <div>
- <asp:Label runat="server" ID="Label2">This is Bottom!</asp:Label>
- </div>
- </form>
- </body>
- </html>
Regards,
Terry