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

Writing to a textbox control inside a template

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 1
Roland asked on 27 Jan 2009, 08:36 PM

Hello,
 I have a telerik grid on my page that is populated using using textboxes in a template setup.

See code bleow:

<telerik:GridTemplateColumn HeaderText="Cash On Hand" UniqueName="cashonhand2">

 

<ItemTemplate>

 

<telerik:RadTextBox runat="server" ID ="txtTemplateCashOnHand" Text = ''></telerik:RadTextBox>

 

 

</ItemTemplate>

 

</telerik:GridTemplateColumn>

 

 

 

ISSUE:
From the code behind in the grid_ItemDataBound event handler, I want to access each textbox(there are 5 in a Row) and write data to the

txtTemplateCashOnHand control.
Any assistance will be highly appreciated.

Thank you.

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 Jan 2009, 06:04 AM
Hi,

I hope you are using 5 TemplateColumns with a RadTextBox in each column's ItemTemplate. You can therefore use the UniqueName property for the column and FindControl method to access the controls in the ItemTemplate of the various columns.
Check out the code below to understand better:
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            RadTextBox rdtxtbx = (RadTextBox)dataItem["cashonhand2"].FindControl("txtTemplateCashOnHand"); 
            rdtxtbx.Text = "Custom Text"
            // Similarly you can access RadTextBox controls in other columns 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Roland
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or