How to i acccess controls with inline code not in itemDataBound

6 posts, 0 answers
  1. Philip
    Philip avatar
    69 posts
    Member since:
    Mar 2016

    Posted 13 Apr 2016 Link to this post

    I i need to be able to access the text boxes within my form popup on rad grid I have tried the usual find controls but to no avail it always returns null. I cannot do it in itemDatabound as I am using a function in my dal which I need to pass the raw value to.


    01.<telerik:RadGrid ID="rgNotes" runat="server" GroupPanelPosition="Top" OnItemCommand="rgNotes_ItemCommand"  >
    02.                                   <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
    03.                                   <MasterTableView NoDetailRecordsText="No notes for this Appointment" AutoGenerateColumns="False" DataKeyNames="notes_id" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Notes" AllowAutomaticInserts="true" EditMode="PopUp">
    04.                                       <Columns>
    05.                                           <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
    06.                                           </telerik:GridEditCommandColumn>
    07.                                           <telerik:GridBoundColumn DataField="notes_id" FilterControlAltText="Filter notes_id column" HeaderText="notes_id" ReadOnly="True" SortExpression="notes_id" Visible="true" UniqueName="notes_id">
    08.                                           </telerik:GridBoundColumn>
    09.                                           <telerik:GridBoundColumn DataField="Subject" FilterControlAltText="Filter Subject column" HeaderText="Subject" ReadOnly="True" SortExpression="Subject" UniqueName="Subject">
    10.                                           </telerik:GridBoundColumn>
    11.                                       </Columns>
    13.                                       <EditFormSettings EditFormType="Template" InsertCaption="Add new Note" CaptionFormatString="Please enter or update note">
    14.                                           <FormTemplate>
    16.                                               <telerik:RadTextBox ID="txtNotesId" Visible="false" Width="200px" runat="server"></telerik:RadTextBox>
    18.                                               Subject
    19.                                               <p>
    20.                                                   <telerik:RadTextBox ID="txtSubjectNotes" Width="200px" runat="server"></telerik:RadTextBox>
    21.                                               </p>
    22.                                               <p>
    23.                                                   Notes<br />
    24.                                                   <telerik:RadTextBox ID="RadTextBox1" TextMode="MultiLine" Rows="10" Columns="10" Width="200px" runat="server"></telerik:RadTextBox>
    25.                                               </p>
    27.                                               <telerik:RadButton ID="rdSaveNotes" OnClick="rdSaveNotes_Click" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Save Notes"></telerik:RadButton>
    28.                                               <telerik:RadButton ID="rdCancel" OnClick="rdCancel_Click1" CommandName="Cancel" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Cancel"></telerik:RadButton>
    29.                                           </FormTemplate>
    30.                                       </EditFormSettings>
    31.                                   </MasterTableView>
    32.                                   <ClientSettings>
    33.                                       <ClientEvents OnPopUpShowing="PopUpShowing" />
    34.                                       <Selecting AllowRowSelect="true" />
    35.                                   </ClientSettings>
    36.                               </telerik:RadGrid>

    01.protected void rdSaveNotes_Click(object sender, EventArgs e)
    03.    try
    04.    {
    05.        int id = Convert.ToInt32(Request.QueryString["id"]);
    06.        tblApertureNetNote _note = new tblApertureNetNote();
    08.        _note = _dal.GetNotesById(new Guid(notes_id),_myuser.UserId);
    10.        _note.appointment_id = id;
    11.        _note.authUserId = _myuser.UserId;
    12.        _note.isActive = true;
    13.        _note.isDeleted = false;
    14.        _note.subject = txtSubject.Text;
    15.        if (_note.EntityState == System.Data.EntityState.Detached)
    16.            _dal.Addnotes(_note);
    18.        rgNotes.DataBind();
    19.    }
    20.    catch (Exception ex)
    21.    {
    22.        logger.Error("Error in rdSaveNotes_Click function calandar edit.aspx" + ex.ToString());
    23.    }


    It is txtSubjectNotes.Text i require to access and Notes textbox Please can you advise also how can i close the popup from this button. Many thanks.

  2. Philip
    Philip avatar
    69 posts
    Member since:
    Mar 2016

    Posted 13 Apr 2016 in reply to Philip Link to this post

    I tried the following but again null !


          GridEditFormItem item = (GridEditFormItem)rgNotes.MasterTableView.GetItems(GridItemType.EditFormItem)[0];
                    TextBox txtSubjectNotes = (TextBox)item["txtSubjectNotes"].Controls[0];
                    TextBox txtMultiNotes = (TextBox)item["txtMultiNotes"].Controls[0];

  3. Philip
    Philip avatar
    69 posts
    Member since:
    Mar 2016

    Posted 14 Apr 2016 in reply to Philip Link to this post

    Still having an issue here with it returning null cant anyone help me out here
  4. Viktor Tachev
    Viktor Tachev avatar
    2501 posts

    Posted 14 Apr 2016 Link to this post

    Hi Philip,

    Check out the article below that illustrates how you can access the RadGrid cells in edit mode.

    With that said, I noticed that you are using DataBind() method to bind the RadGrid. Note that this method is used for simple data binding. As the name implies this type of binding is suitable only for the most simple scenarios for RadGrid when operations like grouping, filtering, sorting, etc. will not be used. Moreover this binding does not support EditForm Templates.

    In order to implement the behavior you should use advanced data binding for RadGrid. You can bind the grid to a declarative DataSource control or via the NeedDataSource event. Please examine the following resources that describe both approaches in more detail:

    Viktor Tachev
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  5. Philip
    Philip avatar
    69 posts
    Member since:
    Mar 2016

    Posted 14 Apr 2016 in reply to Viktor Tachev Link to this post

    As I stated I must do this in page load and save routine which using business logic Why cant i simply find it using FindControl this should be the case !
  6. Viktor Tachev
    Viktor Tachev avatar
    2501 posts

    Posted 15 Apr 2016 Link to this post


    You can use other events to get reference of the controls in the EditForm. The code snippet below outlines how you can use a Button Click event.

    protected void Button1_Click(object sender, EventArgs e)
        var editFormItems = RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem);
        foreach (GridEditFormItem item in editFormItems)
            if (!item.IsInEditMode)
            var textBox = item.FindControl("TextBox1");
            //add custom logic here

    With that said, if you would like to use EditForm template you should use advanced data binding for RadGrid.

    Viktor Tachev
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top