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

Change ItemTemplate binding code behind

1 Answer 487 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 16 May 2016, 11:27 AM

Hello,

I would like to change the binding of the ItemTemplate of a GridTemplateColumn in code behind. I am trying to use the click event of a button outside of the grid to change the binding. On the button click, I would like change the Text value of the ItemTemplate to '<%#Eval("Choose")%>'. Please assist.

APSX:

<telerik:GridTemplateColumn HeaderText="SSA Decision" SortExpression="SSA_Decision" UniqueName="SSA_Decision">
<ItemTemplate>
    <asp:Label ID="lblSSADecision" runat="server" Text='<%#Eval("SSA_Decision")%>' />
</ItemTemplate>
<EditItemTemplate>
    <telerik:RadComboBox runat="server" ID="cboSSADecision" Skin="WebBlue" Width="105px">
    <Items>
            <telerik:RadComboBoxItem Text="Yes" Value="True" />
            <telerik:RadComboBoxItem Text="No" Value="False" />
            <telerik:RadComboBoxItem Text="Please Choose" Value="Choose" Selected="true" />
    </Items>
    </telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>

Thanks!

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 19 May 2016, 05:59 AM
Hi Patrick,

Generally, you can define 2 Label controls and toggle their Visible property depending on the chosen option. Alternatively, you can remove the Text property from the mark-up definition and use the ItemDataBound event handler to set the text using the labelControl.Text=DataBinder.Eval(gridDataItem.DataItem, "FieldName") approach:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values

I hope this will prove helpful.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Patrick
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or