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

Edit/Update RadGrid Row by Index

2 Answers 37 Views
Forum suggestions
This is a migrated thread and some comments may be shown as answers.
Sana
Top achievements
Rank 1
Sana asked on 08 Jul 2019, 11:14 AM

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.

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

 

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)
{
 try
    {
     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 Answers, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 10 Jul 2019, 03:36 PM
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">
    <ItemTemplate>
        <telerik:RadLabel ID="RadLabel1" runat="server" Text='<%# Eval("Firstname") %>'></telerik:RadLabel>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind("Firstname") %>'></telerik:RadTextBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

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.
0
Sana
Top achievements
Rank 1
answered on 24 Jul 2019, 06:28 AM
Thank you Attila for your response and detailed explanation.
Tags
Forum suggestions
Asked by
Sana
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Sana
Top achievements
Rank 1
Share this question
or