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

How to get value of textbox in FormTemplate ItemCommand event

4 Answers 453 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DJ
Top achievements
Rank 1
DJ asked on 06 Jan 2009, 03:38 AM
After going through the documentation and looking a several forum posts, I am still having trouble getting a reference to a textbox inside a FormTemplate:

<FormTemplate>
   <asp:TextBox ID="MyTextbox" runat="server" Text='<%# Bind( "some_value_from_database") %>' Columns="80" />
                                
    <asp:Button ID="SendTestEmail" Text='Send Test Email' runat="server" CommandName='some_command' CommandArgument='<%# Eval("some_database_ID") %>' />
</FormTemplate>

and in code behind:

 protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == "some_command")
        {
             //what goes here to read the value of the TextBox?
        }
    }

Thanks for the fantastic product. I've been using Telerik controls for 3 years now.

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jan 2009, 04:13 AM
Hi DJ,

Give a try with the following code snippet and see whether it helps.

CS:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "some_command")  
        {  
            GridEditFormItem editform = (GridEditFormItem)((Telerik.Web.UI.GridDataItem)(e.Item)).EditFormItem;  
            TextBox txtbx = (TextBox)editform.FindControl("MyTextbox");  
            string strtxt = txtbx.Text;  
        }  
    }  
  
 
 

Thanks
Shinu
0
DJ
Top achievements
Rank 1
answered on 07 Jan 2009, 01:35 AM
You solution worked perfectly. Thank you!
0
aashis
Top achievements
Rank 1
answered on 09 Feb 2011, 05:04 PM
Hi,
I'm Aashis, I'm new to the Telerik . I did exactly what you suggested. But i'm getting old values from the fields. I tried different other methods but still i'm getting old values.

My code look like....
<telerik:RadGrid
            ID="marketVolatilityGrid"
            AutoGenerateColumns="False"
            AllowSorting="true"
            AllowPaging="true"
            AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True"            
            PopUpSettings-Modal="true"
            OnUpdateCommand="updateMarketVolatility"
            PageSize="10"            
            runat="server" >
            <ClientSettings EnableRowHoverStyle="false">
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
            <MasterTableView DataKeyNames="Market" EditMode="PopUp"  CommandItemDisplay="Top">
                <Columns>
                    <telerik:GridBoundColumn DataField="market" UniqueName="market" HeaderText="Market" />
                    <telerik:GridBoundColumn DataField="market_nme" UniqueName="market_nme" HeaderText="Market Name" />
                    <telerik:GridBoundColumn DataField="volatility" UniqueName="volatility" HeaderText="Volatility" />
                    <telerik:GridBoundColumn DataField="start_date" UniqueName="start_date" HeaderText="Start Date" />
                    <telerik:GridBoundColumn DataField="end_date" UniqueName="end_date" HeaderText="End Date" />
                    <telerik:GridEditCommandColumn ></telerik:GridEditCommandColumn>                    
                </Columns>  
                <EditFormSettings CaptionFormatString="Market Volatility" EditFormType="Template">
                    <PopUpSettings Modal="true" Width="500px" />                    
                    <FormTemplate>
                        <div class="formContainer">
                            <div class="formBox">            
                                <span class="labelBox"><asp:Label ID="lblMarket" Text="Market" runat="server" /></span>
                                <span class="labelField">
                                    <asp:TextBox ID="txtMarket" runat="server" CssClass="txtLngField" Text='<%# DataBinder.Eval( Container, "DataItem.market" ) %>' />
                                </span>
                            </div>        
                            <asp:Label ID="lblEdit" runat="server"></asp:Label>
                            <div class="formBox">
                                <asp:Button runat="server" Text="Update" ID="btnUpdate" CommandName="update"  />
                                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="cancel"   />
                            </div>      
                        </div>
                    </FormTemplate>
                </EditFormSettings>                  
                <NoRecordsTemplate>There are no records to display</NoRecordsTemplate>                                
            </MasterTableView>
        </telerik:RadGrid>
this is my aspx.... and code behind it is ..

protected void updateMarketVolatility(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditFormItem editform = (GridEditFormItem)((Telerik.Web.UI.GridDataItem)(e.Item)).EditFormItem;
            string market = string.Empty;
            TextBox mrkt = (TextBox)editform.FindControl("txtMarket");
            market = mrkt.Text; // this fetch old value from the control
        }
0
Princy
Top achievements
Rank 2
answered on 10 Feb 2011, 05:38 AM
Hello DJ,

Please go through the following documentation which shows how to get the new values in UpdateCommand.
Updating values using UserControl/FormTemplate

Thanks,
Princy.
Tags
Grid
Asked by
DJ
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
DJ
Top achievements
Rank 1
aashis
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or