Change ItemTemplate binding code behind

2 posts, 0 answers
  1. Patrick
    Patrick avatar
    11 posts
    Member since:
    May 2009

    Posted 16 May Link to this post

    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!

  2. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 19 May Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top