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

Way to access FormTemplate fields from code-behind?

1 Answer 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
ToltingColtAcres asked on 01 Nov 2013, 02:56 PM

Given the following code example, is there a way to access "RadTextBox_Name" in code-behind prior to initiating an Edit operation on the record? e.g. in the RadGrid onItemCommand event (CommandName="Edit") is there a way to manipulate the attributes of RadTextBox_Name prior to the pop-up appearing? My real-world application is a bit more complicated than this (e.g. I have several fields and want to have some enabled/disabled based on values in other fields, etc.) but for purposes of my question, the below code example is adequate.


<telerik:RadGrid ID="RadGrid_Products" runat="server" AutoGenerateColumns="False" AllowAutomaticUpdates="True"  DataSourceID="SqlDataSource_Products">
<MasterTableView DataKeyNames="Key" EditMode="PopUp" commanditemdisplay="Bottom" >
  <Columns>
   <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn1" />
   <telerik:GridBoundColumn DataField="Key" HeaderText="Key" UniqueName="Key" />
   <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" />
  </Columns>
  <EditFormSettings EditColumn-UniqueName="EditCommandColumn1" EditFormType="Template" CaptionDataField="Name" >
   <FormTemplate>
     <table width="100%">
      <tr>
       <td width="10%" align="right">
        Name:
       </td>
       <td width="90%">
        <telerik:RadTextBox ID="RadTextBox_Name" runat="server" width="100%" Text='<%# Bind("Name" ) %>' />
       </td>
      </tr>
     </table>
    </FormTemplate>
  </EditFormSettings>
 </MasterTableView>
</RadGrid>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Nov 2013, 05:09 AM
Hi ,

Please try the following code snippet to access the RadTextBox of EditForm in edit mode.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem edit = (GridEditFormItem)e.Item;
        //Access 'RadTextBox_Name' RadTextBox in EditForm during Edit mode
        RadTextBox radtxt = (RadTextBox)edit.FindControl("RadTextBox_Name");           
    }
}

Thanks,
Princy
Tags
Grid
Asked by
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
Answers by
Princy
Top achievements
Rank 2
Share this question
or