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

Get values from Textbox in <telerik:GridTemplateColumn>

1 Answer 698 Views
Grid
This is a migrated thread and some comments may be shown as answers.
io
Top achievements
Rank 1
io asked on 31 Jan 2020, 05:15 PM

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">  
        <ItemTemplate>
               <asp:Textbox ID="txtNota" runat="server" CssClass="form-control form-control-sm" ></asp:Textbox> 
        </ItemTemplate> 
</telerik:GridTemplateColumn>

 

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)
        {
            try
            {
                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("IdHerramienta");
                    //dtHtasSeleccionadas.Columns.Add("Codigo");
                    //dtHtasSeleccionadas.Columns.Add("NombreCorto");
                    //dtHtasSeleccionadas.Columns.Add("Cantidad");
                    //dtHtasSeleccionadas.Columns.Add("Costo", typeof(double));
                    //dtHtasSeleccionadas.Columns.Add("Gasto", typeof(double));
                    //dtHtasSeleccionadas.Columns.Add("Nota");
                    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 ""

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 05 Feb 2020, 10:21 AM

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">
    <ItemTemplate>
        <asp:TextBox ID="txtNota" runat="server" Text='<%# Bind("TheFieldThatNeedsToBeUpdated") %>'></asp:TextBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>

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.
Tags
Grid
Asked by
io
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or