Find control in RadGrid editarea

5 posts, 1 answers
  1. Carl-Johan
    Carl-Johan avatar
    22 posts
    Member since:
    May 2008

    Posted 23 Oct 2008 Link to this post

    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

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Oct 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Carl-Johan
    Carl-Johan avatar
    22 posts
    Member since:
    May 2008

    Posted 24 Oct 2008 Link to this post

    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>

     
    (I have removed a lot of unnecessary code).
    As you can see the label in question is positioned under <EditFormSettings><FormTemplate> in a table.  
    What am I missing?  

    Thanks  

    Kalle

  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Oct 2008 Link to this post

    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
  6. Carl-Johan
    Carl-Johan avatar
    22 posts
    Member since:
    May 2008

    Posted 25 Oct 2008 Link to this post

    That did the trick.

    Thanks

    Kalle
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017