Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Ajax Uploader
»
Re: putting an an ajax uploader in a repeater
putting an an ajax uploader in a repeater
Last post 09-05-2009, 1:57 PM by
Lan-Lord
. 2 replies.
Sort Posts:
Oldest to newest
Newest to oldest
Previous
Next
08-27-2009, 12:27 PM
55119
Lan-Lord
Joined on 08-27-2009
Posts 7
putting an an ajax uploader in a repeater
Reply
Quote
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
cutechat
Joined on 07-22-2004
Posts 2,332
Re: putting an an ajax uploader in a repeater
Reply
Quote
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;
c
c
= 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
09-05-2009, 1:57 PM
55391
in reply to
55230
Lan-Lord
Joined on 08-27-2009
Posts 7
Re: putting an an ajax uploader in a repeater
Reply
Quote
Hey thats perfect, thanks for assistance. So far I really like the ajax uploader.