Hello all,
Is there a way to access input control of RadAsyncUpload control from Grid ItemDataBound event?
When grid row is in edit mode, I need to display the file name that user have previously chosen.
I used findControl of RadAsyncUpload control like below. But cannot find child control.
protected void gridMembers_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
RadAsyncUpload ascUpload = e.Item.FindControl("RadAsyncUploadFile") as RadAsyncUpload;
Control l_Control = ascUpload.FindControl(ascUpload.ClientID.Replace(ascUpload.ID, "file1"));
// null
}
}
Thanks in advanced,
Robin
Is there a way to access input control of RadAsyncUpload control from Grid ItemDataBound event?
When grid row is in edit mode, I need to display the file name that user have previously chosen.
I used findControl of RadAsyncUpload control like below. But cannot find child control.
protected void gridMembers_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
RadAsyncUpload ascUpload = e.Item.FindControl("RadAsyncUploadFile") as RadAsyncUpload;
Control l_Control = ascUpload.FindControl(ascUpload.ClientID.Replace(ascUpload.ID, "file1"));
// null
}
}
Thanks in advanced,
Robin
4 Answers, 1 is accepted
0
Accepted

Princy
Top achievements
Rank 2
answered on 09 Oct 2013, 11:00 AM
Hi Robin,
Please try the following code snippet to get the last uploaded file from RadGrid ItemDataBound event.
C#:
Also you can access input control of RadAsyncUpload either by getElementsByTagName or by getElementsByClassName as follows.
C#:
JavaScript:
Thanks,
Princy.
Please try the following code snippet to get the last uploaded file from RadGrid ItemDataBound event.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
RadAsyncUpload RadAsyncUpload1 = (RadAsyncUpload)edit.FindControl(
"RadAsyncUpload1"
);
string
path = Server.MapPath(RadAsyncUpload1.TargetFolder);
DirectoryInfo targetDir =
new
DirectoryInfo(path);
var myFile = targetDir.GetFiles()
.OrderByDescending(f => f.LastWriteTime)
.First();
string
name = myFile.Name;
Label label1 = (Label)edit.FindControl(
"Label2"
);
label1.Text = name;
}
}
Also you can access input control of RadAsyncUpload either by getElementsByTagName or by getElementsByClassName as follows.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
string
script =
"function f(){GetInput("
+ RadAsyncUpload1.ClientID +
"); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"
;
ScriptManager.RegisterStartupScript(Page, Page.GetType(),
"key"
, script,
true
);
}
JavaScript:
<script type=
"text/javascript"
>
function
GetInput(RadAsync) {
var
inputcontrol = RadAsync.getElementsByTagName(
"<input type='file'>"
);
// byTageName
//or
var
inputcontrol = RadAsync.getElementsByClassName(
"ruFileInput"
);
//byClassName
}
</script>
Thanks,
Princy.
0

Robin
Top achievements
Rank 2
answered on 10 Oct 2013, 09:15 AM
This works!!!
Thanks for the support.
Thanks for the support.
0

Ramkumar
Top achievements
Rank 1
answered on 29 Nov 2013, 09:09 AM
How to insert the file using radasyncupload in radgrid item inserrted command???
0

Shinu
Top achievements
Rank 2
answered on 29 Nov 2013, 10:32 AM
Hi Ramkumar,
I guess you want to insert the Uploaded FileName into the DataBase in RadGrid InsertCommand event. Please have a look into the sample code snippet.
ASPX:
C#:
Thanks,
Shinu.
I guess you want to insert the Uploaded FileName into the DataBase in RadGrid InsertCommand event. Please have a look into the sample code snippet.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"false"
OnInsertCommand
=
"RadGrid1_InsertCommand"
OnItemInserted
=
"RadGrid1_ItemInserted"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
UniqueName
=
"OrderID"
HeaderText
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
HeaderText
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShipAddress"
UniqueName
=
"ShipAddress"
HeaderText
=
"ShipAddress"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
>
<
EditItemTemplate
>
<
telerik:RadAsyncUpload
ID
=
"RadAsyncUpload1"
runat
=
"server"
>
</
telerik:RadAsyncUpload
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
Selecting-AllowRowSelect
=
"true"
>
</
ClientSettings
>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_InsertCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.Item
is
GridEditFormInsertItem && e.Item.IsInEditMode)
{
GridEditFormInsertItem editItem = (GridEditFormInsertItem)e.Item;
RadAsyncUpload upload = (RadAsyncUpload)editItem.FindControl(
"RadAsyncUpload1"
);
string
filename= upload.UploadedFiles[0].FileName;
//Query to insert the filename in database
}
}
Thanks,
Shinu.