Change RadComboBox to TextBox in an EditItemTemplate on some rows dependig on data

4 posts, 0 answers
  1. Tonino
    Tonino avatar
    107 posts
    Member since:
    Nov 2007

    Posted 09 Jun Link to this post

    Hello!

     

    I have a grid with RadComboBox in an EditItemTemplate:

     
    <telerik:GridTemplateColumn DataField="Value" HeaderText="Wert">
       <EditItemTemplate>
          <telerik:RadComboBox ID="cboFeatureValue" runat="server" DataSourceID="odsFeatureValueList"
             SelectedValue='<%# Bind("Value") %>' DataTextField="Text" DataValueField="Value"
             Skin="Default">
          </telerik:RadComboBox>
       </EditItemTemplate>
       <ItemTemplate>
          <asp:Label ID="lblFeatureValue" runat="server" Text='<%# Eval("Value") %>'></asp:Label>
       </ItemTemplate>
    </telerik:GridTemplateColumn>

     

    On some rows, depending on the data, I need a TextBox instead of the RadComboBox. Any idea how to achieve this?

     

    I tried adding the TextBox in the EditITemTemplate and disabling the not wanted control:

    <asp:TextBox runat="server" Text='<%# Bind("Value") %>' ID="txtFeatureValue"/>

    and in here I disable the not wanted control:

    Private Sub grdFeatureList_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles grdFeatureList.ItemDataBound
       If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
          Dim dataItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
          If _FeatureParameter.Contains("Enum") Then
             Dim textBox As TextBox = CType(dataItem.FindControl("txtFeatureValue"), TextBox)
             textBox.Enabled = False
             textBox.Visible = False
          Else
             Dim radComboBox As RadComboBox = CType(dataItem.FindControl("cboFeatureValue"), RadComboBox)
             radComboBox.Enabled = False
             radComboBox.Visible = False
          End If
       End If
    End Sub

     

     

    The problem is, that the Selecting event of the RadComboBox is called before I can disable the ComboBox. And as I don't have any data for the combo box I get an "Selection out of range" exception.

     

    Thanks for helping!

     

    Regards,

    Tonino.

  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 14 Jun Link to this post

    Hi Tonino,

    Try to execute the logic on ItemCreated instead of ItemDataBound. If the error remains, you can clear the SelectedValue="" property of the combo, for example during the ItemCreated event of the grid or DataBinding  or Init event handlers of the combo itself.

    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
  4. Tonino
    Tonino avatar
    107 posts
    Member since:
    Nov 2007

    Posted 14 Jun in reply to Eyup Link to this post

    Hi Eyup!

    Using ItemCreated is working, thank you!

    Now I get a dropdown box in edit mode. The textbox is edit mode is not working. Is something wrong with the TextBox I added in the EditItemTemplate?

     

    Regards,

    Tonino.

     

  5. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 17 Jun Link to this post

    Hello Tonino,

    Try placing the TextBox definition before the RadComboBox. If the issue remains, you can create 2 separate columns for these controls, hide one of the columns using its Visible or Display property, and toggle visibility of the generated editing controls by using editedItem["ColNameGoesHere"].Parent.Visible="false":
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

    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.
Back to Top