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

problem with UpdateCommand

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mww
Top achievements
Rank 1
mww asked on 07 Oct 2009, 03:28 PM
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 ?

1 Answer, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 07 Oct 2009, 03:52 PM
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  
    } 
Tags
Grid
Asked by
mww
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Share this question
or