Get values from Textbox in <telerik:GridTemplateColumn>

2 posts, 0 answers
  1. io
    io avatar
    6 posts
    Member since:
    Jan 2020

    Posted 31 Jan Link to this post

    I have a radgrid with a Textbox inside a telerik:GridTemplateColumn


    <telerik:GridTemplateColumn  HeaderText="<%$ Resources:Language, lbl_rg_nota %>" UniqueName="Nota" AllowFiltering="false" ReadOnly="true">  
                   <asp:Textbox ID="txtNota" runat="server" CssClass="form-control form-control-sm" ></asp:Textbox> 


    I want to get access to the values the user writes in the textboxes after they click the save button, this is the code behind the button


    protected void btnLevantaPeticion_OnClick(object sender, EventArgs e)
                    var dtHtasSeleccionadas = (Session["dtHtasSeleccionadas"] != null) ? (DataTable)Session["dtHtasSeleccionadas"] : new DataTable();
                    var Folio = CDatos.SP_PeticionesAlmacen.SP_MaxFolio();
                    foreach (GridDataItem item in rgHerramientas.MasterTableView.Items)
                        TextBox txtNota = item.FindControl("txtNota") as TextBox;
                        ShowMessage(txtNota.ToString(), "success");
                    DataTable dt = (DataTable)Session["dtHtasSeleccionadas"];
                    foreach(DataRow dr in dt.Rows)
                        //dtHtasSeleccionadas.Columns.Add("Costo", typeof(double));
                        //dtHtasSeleccionadas.Columns.Add("Gasto", typeof(double));
                        for (int i = 0; i< int.Parse(dr.ItemArray[4].ToString()); i++)
                            var id2 = CDatos.DDetalles.InsertDetallePeticiones(int.Parse(Folio.ToString()),int.Parse(dr.ItemArray[0].ToString()),1,decimal.Parse(dr.ItemArray[5].ToString()),1,"");   
                    this.ShowMessage(Resources.Language.mess_peticion, "success");
                catch (Exception ex) { this.ShowMessage(ex.Message, "danger"); }


    I want to be able to save the data from the textboxes as the last paramenter of the InsertCommand, instead of the ""

  2. Attila Antal
    Attila Antal avatar
    573 posts

    Posted 05 Feb Link to this post

    Hi Io,

    When using template columns, the developer working with it must make sure the Controls in the template are bound using the Bind() expression like in the example below:

    <telerik:GridTemplateColumn HeaderText="<%$ Resources:Language, lbl_rg_nota %>" UniqueName="Nota" AllowFiltering="false" ReadOnly="true">
            <asp:TextBox ID="txtNota" runat="server" Text='<%# Bind("TheFieldThatNeedsToBeUpdated") %>'></asp:TextBox>

    When this control is bound using the bind() expression, then the data information will be available in the Inserting/Updating event arguments. 

    See how this demo has the binding Grid - Form Template Edit Form.

    The following example shows how to extract the data Update all, individual or selected rows using RadGrid with InPlace edit mode


    Kind regards,
    Attila Antal
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
Back to Top