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

Combobox hide item

4 Answers 301 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 12 Oct 2011, 08:15 AM
Hi, I have a databound rad combo box. Is it possible to hide a specific item based on its value or index?

Your assistance will be appreciated.
Thanks.

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 12 Oct 2011, 10:03 AM
HelloDerek,

You can try the following code snippet in the ItemDataBound event of the RadComboBox.
C#:
protected void RadComboBox2_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
 {
    if (e.Item.Text == "5")
     {
         RadComboBoxItem item = e.Item as RadComboBoxItem;
         item.Visible = false;
     }
 }

Thanks,
Shinu.
0
Derek
Top achievements
Rank 1
answered on 12 Oct 2011, 11:22 AM
Thanks Shinu, That did the trick.

If I could just run another one by you.
I have radgrid databound, on edit (Inline Edit) I wish to use a dropdownlist for a field and populate certain items e.g Date, Time etc.
However it should show the databound field when out of edit mode.

 Ive tried the below but on edit the dopdownlist doesnt seem to populate.

Thanks

 

<%--Aspx--%>

 

<telerik:GridTemplateColumn UniqueName="YFieldName" HeaderText="YFieldName">

 <ItemTemplate>

 <%# Eval("YFieldName") %>

</ItemTemplate>

 <EditItemTemplate>

  <asp:DropDownList runat="server" ID="YField">

 </asp:DropDownList>

 </EditItemTemplate>

 </telerik:GridTemplateColumn>

<%--Aspx.vb--%>

 

Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then

 

Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)

Dim dropDownList As DropDownList = DirectCast(item("YFieldName").FindControl("YField"), DropDownList)

DropDownList.DataSource =

New [String]() {"Date", "Time", "Year"}

DropDownList.DataBind()

End If
End Sub


0
Princy
Top achievements
Rank 2
answered on 12 Oct 2011, 11:38 AM
Hello Derek,

I have tried the same code at my end and the DropDownList populated correctly. Please make sure the loop is getting executed. Also ensure that the EditMode is InPlace.

Thanks,
Princy.
0
Derek
Top achievements
Rank 1
answered on 19 Oct 2011, 08:03 AM
Thanks Princy,

It did work, had a typo myside.
Tags
ComboBox
Asked by
Derek
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Derek
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or