Edit/Update RadGrid Row by Index

3 posts, 1 answers
  1. Sana
    Sana avatar
    3 posts
    Member since:
    Jul 2019

    Posted 08 Jul 2019 Link to this post

    Hello Guys,

    I am new to Telerik Radgrid. I need your help. I have a radgrid with ItemTemplate and TextBox in template. Ive a selection window which pops up on TextBox inside grid is clicked and upon selecting some data value should set in that particular TextBox.

    <telerik:GridTemplateColumn DataField="CA_ACC_CODE" HeaderText="Account Code" ItemStyle-BorderColor="#d6d6d6" SortExpression="CA_ACC_CODE" UniqueName="CA_ACC_CODE">
    <asp:TextBox ID="txtAccountCode" OnClick="return showPopUp(this)" Text='<%# Bind("CA_ACC_CODE")%>' runat="server"  Width="120px" Skin="Office2007"></asp:TextBox>
      <ItemStyle BorderColor="#D6D6D6" /> </telerik:GridTemplateColumn>


    The problem I am facing how to iterate and set value in particular textbox. Currently the textbox value is setting in first row of grid only in ItemDataBound event regardless of any row where I click the textbox.

    protected void gv_BO_ItemDataBound(object sender, GridItemEventArgs e)
         string Selectd_row = (string)(Session["coa_selectd_row"]);
         if (Selectd_row == null || Selectd_row == "")
            Selectd_row = "0";
         if (e.Item.RowIndex == int.Parse(Selectd_row))
          if (e.Item is GridEditFormItem)
             GridEditFormItem item = (GridEditFormItem)e.Item;  
             string cc_code = (string)(Session["cc_code"]);
             string cc_title = (string)(Session["cc_title"]);
             string ca_code = (string)(Session["coa_code"]);
             string ca_title = (string)(Session["coa_title"]);
        TextBox txtCostCentre = (TextBox)item["CC_COSTCNTR_CODE"].FindControl("txtCostCentre");
           TextBox txtCCDesc = (TextBox)item["CC_DESC"].FindControl("txtCCDesc");
           TextBox txtAccountCode = (TextBox)item["CA_ACC_CODE"].FindControl("txtAccountCode");
           TextBox txtAccountTitle = (TextBox)item["CA_TITLE"].FindControl("txtAccountTitle");
           txtCostCentre.Text = cc_code;
           txtCCDesc.Text = cc_title;
           txtAccountCode.Text = ca_code;
           txtAccountTitle.Text = ca_title;                   
    catch (Exception ex)
        { }
  2. Answer
    Attila Antal
    Attila Antal avatar
    497 posts

    Posted 10 Jul 2019 Link to this post

    Hi Sana,

    When using Template columns, there are multiple containers used for different purposes. 

    The ItemTemplate container is used to display the data, while the EditItemTemplate is for holding controls that you can use to input data such as (Textboxes, ComboBoxes, etc..).

    Here is an example for a Template Column:

    <telerik:GridTemplateColumn DataField="Firstname">
            <telerik:RadLabel ID="RadLabel1" runat="server" Text='<%# Eval("Firstname") %>'></telerik:RadLabel>
            <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind("Firstname") %>'></telerik:RadTextBox>

    Furthermore, the Data-Binding expressions used (Eval and Bind) are also serving for different purposes. Eval is a read-only method to display data while the Bind() is a two way binding method used to get/set data. See Data-Binding Expressions Overview

    Use Eval, to display data or Bind for controls that are supposed to update data (controls in the EditItemTemplate for instance).

    Once you have a better understanding on the Columns and binding expressions, you can check out the following demos to see which are the different editing the grid can provide:
    I hope this will help get a better understanding.

    Kind regards,
    Attila Antal
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Sana
    Sana avatar
    3 posts
    Member since:
    Jul 2019

    Posted 24 Jul 2019 in reply to Attila Antal Link to this post

    Thank you Attila for your response and detailed explanation.
Back to Top