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

Find control in RadGrid editarea

4 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carl-Johan
Top achievements
Rank 1
Carl-Johan asked on 23 Oct 2008, 01:55 PM

Hi,

I have s small problem.

I have tried the demo Grid/DataEditing/TemplateFormUpdate. It works great (of course) but I would like to change one thing.

 

The result label should be inside the Template edit area:

 

<EditFormSettings EditFormType="Template">

    <FormTemplate>Here!

 

But I cant reach that. The original code in the demo is:

private void DisplayMessage(bool isError, string text)
{
    Label label = (isError) ? this.Label1 : this.Label2;

    label.Text = text;

}

 

I use:

private void DisplayMessage(bool isError, string text)

{

    Label errorLabel = (Label)FindControlRecursiveBobBooksRadGrid, "Label2");

    errorLabel.Text = text;

}

 

The reason to this is that I use a lot of server-side error checking and throw different Exceptions. I catch them and presents the information in a label that I have put next to the textboxes.

 

I catch the error like this:

if (e.Exception != null)

{

    e.KeepInEditMode = true;

    e.ExceptionHandled = true;

    DisplayMessage(true, e.Exception.Message);

}

 

So my question is: whats the best way to run the server-side error checking raise an exception (when needed) and present the result in a label next to the textboxes.

Thanks

Kalle

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Oct 2008, 06:08 AM
Hi,

You can access the controls in the edit form in the ItemUpdated  event as shown below:
CS:
protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e) 
        { 
            GridEditableItem editedItem = (GridEditableItem)e.Item; 
            Label label = (Label)editedItem.FindControl("Label1"); 
 
             
        } 
 

Thanks,
Princy
0
Carl-Johan
Top achievements
Rank 1
answered on 24 Oct 2008, 06:34 AM

Thank you for your quick reply.  
It still doesn’t work though.  
Here is my code in the .cs file:

protected void BobBooksRadGrid_ItemUpdated(object source, GridUpdatedEventArgs e)

{

 if (e.Exception != null)

 {

 

   GridEditableItem editedItem = (GridEditableItem)e.Item;

 

   Label label = (Label)editedItem.FindControl("nameErrorLabel");

   label.Text = "Error text";

   e.KeepInEditMode = true;

   e.ExceptionHandled = true;

 }

}

And here is my code in the .aspx file:

<EditFormSettings EditFormType="Template">

 <FormTemplate>

  <table>

   <tr>

    <td><asp:Label ID="nameErrorLabel" runat="server" Text="Label"></asp:Label>&nbsp;

    </td>

   </tr>

0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Oct 2008, 09:35 AM
Hi,

A suggestion would  be to use a global variable and set it to a value when exception occurs. When the  grid rebinds then  in the ItemDataBound event you can  set the error text in your edit form as shown below:

CS:
 public int flag=0
  protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e) 
        { 
            if (e.Exception != null) 
            { 
                e.KeepInEditMode = true
                e.ExceptionHandled = true
                flag = 1
            }  
        } 
 
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if(e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem editedItem = (GridEditableItem)e.Item; 
                if (f;lag == 1) 
                { 
                    Label label = (Label)editedItem.FindControl("Label1"); 
                    label.Text = "Error text"
                } 
            } 
                
        } 

Thanks,
Princy
0
Carl-Johan
Top achievements
Rank 1
answered on 25 Oct 2008, 02:35 PM
That did the trick.

Thanks

Kalle
Tags
Grid
Asked by
Carl-Johan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Carl-Johan
Top achievements
Rank 1
Share this question
or