2016-04-07 86 views
0

我正在試圖找到Telerik RadGrid編輯窗體中的控件。我需要能夠在頁面加載中做到這一點,但是我見過的大多數例子都只是在itemDataBound上,但我需要能夠在頁面加載時設置一個值並在點擊按鈕時保存一個值。在Telerik RadGrid中找不到控件

<telerik:RadGrid ID="rgNotes" runat="server" GroupPanelPosition="Top"> 
    <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings> 
    <MasterTableView NoDetailRecordsText="No notes for this Appointment" AutoGenerateColumns="False" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Notes" AllowAutomaticInserts="true" EditMode="PopUp"> 
     <Columns> 
      <telerik:GridEditCommandColumn UniqueName="EditCommandColumn"> 
      </telerik:GridEditCommandColumn> 
      <telerik:GridBoundColumn DataField="Subject" FilterControlAltText="Filter Subject column" HeaderText="subject" ReadOnly="True" SortExpression="Subject" UniqueName="Subject"> 
      </telerik:GridBoundColumn> 
     </Columns> 

     <EditFormSettings EditFormType="Template" InsertCaption="Add new Note"> 
      <FormTemplate> 
       Subject 
       <p> 
        <telerik:RadTextBox ID="txtSubjectNotes" Width="200px" runat="server"></telerik:RadTextBox> 
       </p> 
       <p> 
       </p> 

       <telerik:RadButton ID="rdSaveNotes" OnClick="rdSaveNotes_Click" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Save Notes"></telerik:RadButton> 
       <telerik:RadButton ID="rdCancel" OnClick="rdCancel_Click1" CommandName="Cancel" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Cancel"></telerik:RadButton> 
      </FormTemplate> 
     </EditFormSettings> 
    </MasterTableView> 
    <ClientSettings> 
     <ClientEvents OnPopUpShowing="PopUpShowing" /> 
     <Selecting AllowRowSelect="true" /> 
    </ClientSettings> 
</telerik:RadGrid> 

舉個例子,我試圖訪問它在後面的代碼在我保存的事件。

protected void rdSaveNotes_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     int id = Convert.ToInt32(Request.QueryString["id"]); 
     tblApertureNetNote _note = new tblApertureNetNote(); 
     _note.appointment_id = id; 

     _note.isActive = true; 
     _note.isDeleted = false; 
     _note.subject = txtSubjectNotes.Text; //It's here i can't find the textbox 

     _dal.Addnotes(_note); 
     rgNotes.DataBind(); 
    } 
    catch (Exception ex) 
    { 
     logger.Error("Error in rdSaveNotes_Click function calandar edit.aspx" + ex.ToString()); 
    } 
} 

回答

0

這是因爲當控件放置在一個網格,他們不是在設計文件頁面控件聲明。

你將不得不持有它們。在保存按鈕點擊的情況下,您應該能夠獲得與該按鈕相關的文本框。

嘗試:

var button = (Control)sender; // sender is the button 

// then ask the button's parent control to find the textbox 
var txtSubjectNotes = button.Parent.FindControl("txtSubjectNotes") as RadTextBox; 

if(txtSubjectNotes != null) 
{ 
    // make sure it's not null 
    _note.subject = txtSubjectNotes.Text; 
}