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

ItemTemplate : Change Control Binding At Runtime

2 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 25 Mar 2010, 07:58 PM
Hi All,

I have an ItemTemplate with a RadNumericTextBox bound as follows:-

<ItemTemplate> 
    <telerik:RadNumericTextBox ID="RadNumericTextBox_cost" Runat="server"  
            Culture="English (United Kingdom)"  
            Type="Currency"  
            Width="60px" Text='<%# Eval("cost") %>' MinValue="0" MaxValue="5500"  
            EnabledStyle-HorizontalAlign="Right" FocusedStyle-HorizontalAlign="Right"
        <FocusedStyle HorizontalAlign="Right" /> 
        <EnabledStyle HorizontalAlign="Right" /> 
    </telerik:RadNumericTextBox> 
</ItemTemplate> 

In some instances I wish to change the binding of the control at runtime ie costAdjust rather than cost

<ItemTemplate> 
    <telerik:RadNumericTextBox ID="RadNumericTextBox_cost" Runat="server"  
            Culture="English (United Kingdom)"  
            Type="Currency"  
            Width="60px" Text='<%# Eval("costAdjust") %>' MinValue="0" MaxValue="5500"  
            EnabledStyle-HorizontalAlign="Right" FocusedStyle-HorizontalAlign="Right"
        <FocusedStyle HorizontalAlign="Right" /> 
        <EnabledStyle HorizontalAlign="Right" /> 
    </telerik:RadNumericTextBox> 
</ItemTemplate> 

I have tried the following:-

Dim costAdjust As RadNumericTextBox = (DirectCast(dg_detailRecovery.MasterTableView.Items(0).FindControl("RadNumericTextBox_cost"), RadNumericTextBox)) 
 
costAdjust.Text = "<%# DataBinder.Eval(Container.DataItem, 'costAdjust') %>" 
 


But the .Items(0) returns an error.

Does anyone have any ideas how this can be achieved???

Thanx

Marcus

ItemTemplate

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Mar 2010, 05:49 AM
Hi Marcus,

You can access the RadNumericTextBox placed in ItemTemplate in ItemDataBound event and then set the Text property to required field value (after checking for condition, if any).

VB:
 
 Protected Sub RadGrid3_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs)     
    If TypeOf e.Item Is GridDataItem Then 
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
        Dim txtNumeric As RadNumericTextBox = DirectCast((item.FindControl("RadNumericTextBox_cost")), RadNumericTextBox) 
        Dim row As DataRowView = DirectCast(item.DataItem, DataRowView) 
        txtNumeric.Text = row("costAdjust").ToString() 
    End If 
End Sub  

-Shinu
0
Marcus
Top achievements
Rank 1
answered on 29 Mar 2010, 09:17 AM
Works a treat - Thank-you...

Marcus
Tags
Grid
Asked by
Marcus
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Marcus
Top achievements
Rank 1
Share this question
or