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

How to i acccess controls with inline code not in itemDataBound

5 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 13 Apr 2016, 09:04 AM

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>
12. 
13.                                       <EditFormSettings EditFormType="Template" InsertCaption="Add new Note" CaptionFormatString="Please enter or update note">
14.                                           <FormTemplate>
15. 
16.                                               <telerik:RadTextBox ID="txtNotesId" Visible="false" Width="200px" runat="server"></telerik:RadTextBox>
17. 
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>
26. 
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)
02.{
03.    try
04.    {
05.        int id = Convert.ToInt32(Request.QueryString["id"]);
06.        tblApertureNetNote _note = new tblApertureNetNote();
07. 
08.        _note = _dal.GetNotesById(new Guid(notes_id),_myuser.UserId);
09. 
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);
17. 
18.        rgNotes.DataBind();
19.    }
20.    catch (Exception ex)
21.    {
22.        logger.Error("Error in rdSaveNotes_Click function calandar edit.aspx" + ex.ToString());
23.    }
24.}

 

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.

5 Answers, 1 is accepted

Sort by
0
Philip
Top achievements
Rank 1
answered on 13 Apr 2016, 09:37 AM

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];
         

0
Philip
Top achievements
Rank 1
answered on 14 Apr 2016, 07:58 AM
Still having an issue here with it returning null cant anyone help me out here
0
Viktor Tachev
Telerik team
answered on 14 Apr 2016, 09:17 AM
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:



Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Philip
Top achievements
Rank 1
answered on 14 Apr 2016, 09:19 AM
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 !
0
Viktor Tachev
Telerik team
answered on 15 Apr 2016, 11:01 AM
Hello,

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)
        {
            continue;
        }
 
        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.




Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Philip
Top achievements
Rank 1
Answers by
Philip
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or