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

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

3 Answers 281 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tonino
Top achievements
Rank 1
Tonino asked on 09 Jun 2016, 12:30 PM
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.

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 14 Jun 2016, 11:12 AM
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.
0
Tonino
Top achievements
Rank 1
answered on 14 Jun 2016, 12:18 PM

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.

 

0
Eyup
Telerik team
answered on 17 Jun 2016, 09:34 AM
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.
Tags
Grid
Asked by
Tonino
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Tonino
Top achievements
Rank 1
Share this question
or