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

How to prevent finding Control on ItemCreated during Editing

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Qudsia
Top achievements
Rank 1
Qudsia asked on 24 Feb 2009, 07:53 AM
Hi,

I m using RadGrid and Calling usercontrol for Edit and Insert , my scenario is that when i have to display different icons on the each row of grid according to data So for this purpose i have taken one Item Template field in which i have called <asp:image /> and finding that control on Item Created so it bind the image with proper icon which i wanted but when i click on Edi button so it throws exception.
Please Kindly help me out how can i resolve this here's my code.

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        GridEditableItem eeditedItem = e.Item as GridEditableItem;  
        UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);  
 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            if (!e.Item.OwnerTableView.IsItemInserted)  
            {  
 
                ImageButton InsertButton = (userControl.FindControl("btnInsert") as ImageButton);  
                InsertButton.Visible = false;  
 
                if (ViewState["Complete"] == null)  
                {  
                    string[] comp = new string[] { };  
                    Session["CompleteID"] = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"]);  
                    toDoList.ID = Convert.ToInt32(Session["CompleteID"]);  
                    comp = toDoList.SelectIsCompleted();  
                    string a = comp[0];  
                    string b = comp[1];  
                    if (a == "True" || b == "true")  
                    {  
                        TextBox Remarks = (userControl.FindControl("txtRemarks") as TextBox);  
                        Remarks.Enabled = false;  
                        TextBox task = (userControl.FindControl("txtTask") as TextBox);  
                        task.Enabled = false;  
                        RadDatePicker AssignDate = (userControl.FindControl("cmbAssignDate") as RadDatePicker);  
                        AssignDate.Enabled = false;  
                        DropDownList User = (userControl.FindControl("cmbUser") as DropDownList);  
                        User.Enabled = false;  
                        DropDownList task_cat = (userControl.FindControl("cmbCategory") as DropDownList);  
                        task_cat.Enabled = false;  
                        RadDatePicker TargetDate = (userControl.FindControl("cmbTargetDate") as RadDatePicker);  
                        TargetDate.Enabled = false;  
                        ImageButton updateButton = (userControl.FindControl("btnUpdate") as ImageButton);  
                        updateButton.Visible = false;  
                        ImageButton Complete = (userControl.FindControl("ImageButton4") as ImageButton);  
                        Complete.Visible = false;  
                    }  
                    ViewState["Complete"] = "Filled";  
                }  
                else  
                {  
                    Session["CompleteID"] = null;  
                    ViewState["Complete"] = null;  
                }  
 
 
            }  
            else  
            {  
                ImageButton updateButton = (userControl.FindControl("btnUpdate") as ImageButton);  
                updateButton.Visible = false;  
                ImageButton Complete = (userControl.FindControl("ImageButton4") as ImageButton);  
                Complete.Visible = false;  
                ImageButton btnDelete = (userControl.FindControl("ImageButton1") as ImageButton);  
                btnDelete.Visible = false;  
            }  
 
 
        }  
        else   
          
        {  
            if (e.Item is GridDataItem)  
            {  
 
                string Status;  
                Status = objResult.resultDS.Tables[0].Rows[e.Item.ItemIndex]["Status"].ToString();  
 
               if (Status == "Completed")  
               {  
                    Image flag = (Image)e.Item.FindControl("flag");  
                    flag.ImageUrl = "Images/green.gif";  
                    flag.ToolTip = "Complete";  
               }  
               else if (Status == "Pending")  
               {  
                   Image flag = (Image)e.Item.FindControl("flag");  
                   flag.ImageUrl = "Images/red.gif";  
                   flag.ToolTip = "Pending";  
 
               }  
               else  
               {  
                    Image flag = (Image)e.Item.FindControl("flag");  
                    flag.ImageUrl = "Images/blue.gif";  
                    flag.ToolTip = "Assigned";  
                }  
 
           }  
       }  
 
 
    } 
Please reply me asap its urgent, i will be very thankful

Regards,

Maham

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 26 Feb 2009, 05:10 PM
Hi Qudsia,

May I ask you to specify what the exception message is? It will be helpful if you quote the error message in this post in order to assist you further.

Can you also check whether some of the controls in the ItemCreated handler are null? This can appear to be the reason for the exception been thrown.

Additionally, I will suggest you put the definition of the eeditedItem and userControl  inside of the first IF statement.

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Qudsia
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or