How to Show/Hide Rad Combobox items based on array row value in Itemdatabound

3 posts, 0 answers
  1. gc_0620
    gc_0620 avatar
    242 posts
    Member since:
    Feb 2008

    Posted 13 Sep 2012 Link to this post

    Folks,

    I am using VS2010 with RadControls for ASP.NET AJAX Q2 2012 SP1. I would like to hide certain ComboBox items based on Values from an array. Below is my complete code. Any help will be appreciated.
    Thanks
    gc_0620
    ________________
    <telerik:RadComboBox ID="Address_LocationRadComboBox" runat="server" SelectedValue='<%# Bind("Address_Location") %>'
        Text='<%# Bind("Address_Location") %>' Width="150px">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="Florida" Value="Florida" />
            <telerik:RadComboBoxItem runat="server" Text="New Jersey" Value="New Jersey" />
            <telerik:RadComboBoxItem runat="server" Text="New York" Value="New York" />
            <telerik:RadComboBoxItem runat="server" Text="Ohio" Value="Ohio" />
            <telerik:RadComboBoxItem runat="server" Text="Wisconsin" Value="Wisconsin" />
        </Items>
    </telerik:RadComboBox>
     
    .........
     
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
      string[] retrievedLocations = (string[])Session["LocationData"];
      Array.Sort(retrievedLocations);
     
      // Assuming Array retrievedLocations has following Values:
     
      // New Jersey
      // New York
      // Wisconsin
     
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     
        {
            GridEditableItem item = (GridEditableItem)e.Item;
     
            // Beginning of Loop each row in array retrievedLocations until no rows in array
     
            RadComboBox combo = (RadComboBox)item.FindControl("Address_LocationRadComboBox");
     
            foreach (RadComboBoxItem ComboItem in combo.Items)
            {
                if (ComboItem.Value != row value of array retrievedLocations)
                {
                   ComboItem.Visible = false;
                }
                else
                {
                   ComboItem.Visible = true;
                }
     
            }
            
           // End of Loop each row in array retrievedLocations until no rows in array
     
        }
    }


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Sep 2012 Link to this post

    Hi,

    These are the following approaches to hide the ComboBox Item.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
      string[] retrievedLocations = (string[])Session["LocationData"];
      Array.Sort(retrievedLocations);
      
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
      
        {
            GridEditableItem item = (GridEditableItem)e.Item;
      
            for (int i = 0; i < retrievedLocations.Length; i++)
            {
               RadComboBox combo = (RadComboBox)item.FindControl("Address_LocationRadComboBox");
               foreach (RadComboBoxItem ComboItem in combo.Items)
               {
                   if (ComboItem.Value != retrievedLocations[i])
                   {
                      ComboItem.Visible = false;
                   }
                   else
                   {
                      ComboItem.Visible = true;
                   }
                }
            }
        }
    }

    OR

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        string[] retrievedLocations = (string[])Session["LocationData"];
        Array.Sort(retrievedLocations);
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            RadComboBox combo = (RadComboBox)item.FindControl("Address_LocationRadComboBox");
            foreach (RadComboBoxItem ComboItem in combo.Items)
            {
                for (int i = 0; i < retrievedLocations.Length; i++)
                {
     
                     if (ComboItem.Value != retrievedLocations[i])
                     {
                        ComboItem.Visible = false;
                     }
                     else
                     {
                        ComboItem.Visible = true;
                     }
      
                }
            }
        }
    }

    Thanks,
    Shinu.
  3. gc_0620
    gc_0620 avatar
    242 posts
    Member since:
    Feb 2008

    Posted 14 Sep 2012 Link to this post

    Thanks Shinu,

    As always appreciate your support.

    Sincerely

    gc_0620 
Back to Top