problem with UpdateCommand

2 posts, 0 answers
  1. mww
    mww avatar
    257 posts
    Member since:
    Sep 2012

    Posted 07 Oct 2009 Link to this post

    In my grid I have 3 columns, a combo, textbox and RADUpload

    in the UpdateCommand event I create an instance of the combo, textbox and RADUpload
    If the user hasnt uploaded any files, I want to keep the original uploadURL values, How can I get to them from the UpdateCommand Event ?

    the datasource bound to the grid is simply a list of a custom class Ive created
    public class CastMemberObj  
        {  
            public int ID { get; set; }  
            public string CastMemberName { get; set; }  
            public string CastMemberInformation { get; set; }  
            public string PhotoURL { get; set; }  
            public string ThumbnailURL { get; set; }  
            public string Type { get; set; }  
        } 
      So in the UpdateCommande event I simply want to get access to the contents of the original PhotoURL & ThumbnailURL
    These arent displayed in the grid, but they are part of the datasource.

    protected void RadGridCast_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
            {  
                var editableItem = ((GridEditableItem)e.Item);  
                var productId = (int)editableItem.GetDataKeyValue("ID");  
                TheCompanyBL.CastMemberObj castmember = new TheCompanyBL.CastMemberObj();  
                string thumbURL = string.Empty;  
                string ImageURL = string.Empty;  
                string url = TheCompanyBL.Helpers.GetSiteURL();  
                string ImageUploadURL = url + "/Uploads/";  
     
                RadTextBox tb = (RadTextBox)e.Item.FindControl("txbCastMember");  
                if (tb != null)  
                {  
                    castmember.CastMemberName = tb.Text;  
                }  
                else  
                {  
                    castmember.CastMemberName = "";  
                }  
     
                RadComboBox rcb = (RadComboBox)e.Item.FindControl("RadComboBoxType");  
                if (rcb != null)  
                {  
                    castmember.Type = rcb.SelectedValue;  
                }  
                else  
                {  
                    castmember.Type = "";  
                }  
     
                  
     
                TheCompanyBL.CastMemberObj member = (TheCompanyBL.CastMemberObj)e.Item.DataItem;  
                Image img = (Image)e.Item.FindControl("ImageThumbNail");  
                if (null != img)  
                {  
     
                }  
                RadUpload ru = (RadUpload)e.Item.FindControl("RadUploadImage");  
                if (null != ru)  
                {  
                    string target = Server.MapPath(ru.TargetFolder);  
     
                    if (ru.UploadedFiles.Count > 0)  
                    {  
                        string sFileType = ru.UploadedFiles[0].GetExtension();  
                        foreach (UploadedFile f in ru.UploadedFiles)  
                        {  
                            imagemanager.ResizeAndSave(ru.UploadedFiles[0], ImageUploadURL, target, "CastMembers", true, out thumbURL);  
                            imagemanager.ResizeAndSave(ru.UploadedFiles[0], ImageUploadURL, target, "CastMembers", false, out ImageURL);  
                            castmember.ThumbnailURL = thumbURL;  
                            castmember.PhotoURL = ImageURL;  
                        }  
                    }  
                }  
                //retrive entity form the Db  
     
                //update entity's state  
                //editableItem.UpdateValues(castmember);  
                string err = castmembermanager.Update(castmember);  
            } 


    Ive tried to cast the dataItem to my custom class but its always null

    TheCompanyBL.CastMemberObj member = (TheCompanyBL.CastMemberObj)e.Item.DataItem;  

    can anyone help me out ?
  2. Casey
    Casey avatar
    299 posts
    Member since:
    Jul 2009

    Posted 07 Oct 2009 Link to this post

    Mww,

    I use the below to access the value of a cells that are not being displayed. I do this during the ItemCommand of my RadGrid. I hope I understood your scenario correctly and that this helps.

    Thanks,
    Casey

    protected void RadGridCast_UpdateCommand(object source, GridCommandEventArgs e)  
        {  
            // code  
            TheCompanyBL.CastMemberObj member = (TheCompanyBL.CastMemberObj)e.Item.Cells[x].Text.ToString();  
            //'x' represents the index of the cell. You may  
            //have to play around with which number picks the right cell  
            //for my RadGrid the 0 and 1 cells were blank spaces  
        } 
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top