Combobox hide item

5 posts, 1 answers
  1. Derek
    Derek avatar
    8 posts
    Member since:
    Sep 2011

    Posted 12 Oct 2011 Link to this post

    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.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Oct 2011 Link to this post

    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.
  3. Derek
    Derek avatar
    8 posts
    Member since:
    Sep 2011

    Posted 12 Oct 2011 Link to this post

    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


  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Oct 2011 Link to this post

    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.
  5. Derek
    Derek avatar
    8 posts
    Member since:
    Sep 2011

    Posted 19 Oct 2011 Link to this post

    Thanks Princy,

    It did work, had a typo myside.
Back to Top