This is a migrated thread and some comments may be shown as answers.

how to make filename a defaultvalue for an insert parameter

1 Answer 44 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Hamza
Top achievements
Rank 1
Hamza asked on 16 Sep 2011, 05:46 PM
hi all :)

I have a grid with template column, Item mode is a binary Image, and edit mode is a rad upload

how can I get the file name and make it an insert parameter default value ?

here is my code

HTML

<telerik:GridTemplateColumn DataField="Data" HeaderText="Image" UniqueName="Upload">
    <ItemTemplate>
        <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" ImageUrl='<%# Eval("User_AvatarPath") %>'
            AutoAdjustImageControlSize="false" Height="80px" Width="80px"
             />
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" OnClientFileUploaded="OnClientFileUploaded"
            AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576"
             OnValidatingFile="RadAsyncUpload1_ValidatingFile"
             TargetFolder="~/Pic's/Users"
             OverwriteExistingFiles="false" >
        </telerik:RadAsyncUpload>
    </EditItemTemplate>
</telerik:GridTemplateColumn>


C#.net

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Charting;
using Telerik.Web.UI;
using System.Data.SqlClient;
 
public partial class HTKfjksh7869435fds435_ljagut32542GSDFG_lgjdfsh32452GR235GGOJA324_Contros_NewItem_WebUserControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.UpdateParameters["User_AvatarPath"].DefaultValue = _ImagePath;
        SqlDataSource1.InsertParameters["User_AvatarPath"].DefaultValue = _ImagePath;
    }
 
    const int MaxTotalBytes = 1048576; // 1 MB
    int totalBytes;
    private static string _ImageName = "";
    private static string _ImagePath = "~/Pic's/Users/" + _ImageName;
    public bool? IsRadAsyncValid
    {
        get
        {
            if (Session["IsRadAsyncValid"] == null)
            {
                Session["IsRadAsyncValid"] = true;
            }
 
            return Convert.ToBoolean(Session["IsRadAsyncValid"].ToString());
        }
        set
        {
            Session["IsRadAsyncValid"] = value;
        }
    }
 
    public void RadAsyncUpload1_ValidatingFile(object sender, Telerik.Web.UI.Upload.ValidateFileEventArgs e)
    {
         
        if ((totalBytes < MaxTotalBytes) && (e.UploadedFile.ContentLength < MaxTotalBytes))
        {
            e.IsValid = true;
            totalBytes += e.UploadedFile.ContentLength;
            IsRadAsyncValid = true;
            _ImageName = e.UploadedFile.GetName();
             
        }
        else
        {
            e.IsValid = false;
            IsRadAsyncValid = false;
        }
 
 
    }
}



thank you all :)

1 Answer, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 20 Sep 2011, 09:30 AM
Hello Hamza,

Please review the following demos - RadAsyncUpload into Grid and RadUpload into Grid.

Greetings,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Upload (Obsolete)
Asked by
Hamza
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Share this question
or