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

How to pass Form Template Edit Form textbox value to code behind

2 Answers 476 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ILJIMAE
Top achievements
Rank 1
ILJIMAE asked on 18 Aug 2012, 07:10 AM
I have a RADGrid named 'RadGrid1' in my aspx page.

RadGrid1 has a form template edit form and this edit form contains:

  • A text box with an ID 'txtEmail' for editing the email address of the selected record
  • A button with an ID 'ButtonA'

What I am trying to do is:

When user click the 'ButtonA' button,
I want to send the email address information shown in the 'txtEmail' text box of the selected record to the code behind file's 'ButtonA' onClick event procedure.

I need to know the correct syntax/code for doing this.

Code behind file:

protected void ButtonA_Click(object sender, EventArgs e)
{
    string EmailAddress = // How can I get the email address information shown in the ‘txtEmail’
                   //  text box in the Form Template Edit Form
}

Thank you. :D

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Aug 2012, 04:50 PM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"
           OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true" AllowFilteringByColumn="true"
           EnableLinqExpressions="false">
           <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" EditMode="EditForms">
               <CommandItemSettings ShowExportToPdfButton="true" />
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
               <EditFormSettings EditFormType="Template">
                   <FormTemplate>
                       <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                       <br />
                       <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
                   </FormTemplate>
               </EditFormSettings>
           </MasterTableView>
       </telerik:RadGrid>
       <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
              new { ID = 1, Name ="aaa"},
              new { ID = 2, Name = "bbb"},
              new { ID = 3, Name = "ccc"},
              new { ID = 4, Name = "ddd"},
               new { ID = 5, Name ="eee"}
            };
            RadGrid1.DataSource = data;
        }
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
             
        }
 
        protected void Button1_Click(object sender, EventArgs e)
        {
            Button Button1 = sender as Button;
            GridEditFormItem item = Button1.NamingContainer as GridEditFormItem;
            TextBox txtEmail = item.FindControl("txtEmail") as TextBox;
            // Access your textbox here
        }
 
        protected void Button2_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid1.EditItems)
            {
                TextBox txtEmail = item.EditFormItem.FindControl("txtEmail") as TextBox;
                // Access your textbox here
            }
        }


Thanks,
Jayesh Goyani
0
ILJIMAE
Top achievements
Rank 1
answered on 19 Aug 2012, 05:48 AM
Thank you very much for you perfect, crystal clear solution Mr Goyani.
Also, thank you for the bonus button click event code for the button placed outside the form template edit form. :D
Tags
Grid
Asked by
ILJIMAE
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
ILJIMAE
Top achievements
Rank 1
Share this question
or