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

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

2 Answers 303 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 13 Sep 2012, 02:52 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Sep 2012, 06:05 AM
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.
0
gc_0620
Top achievements
Rank 1
answered on 14 Sep 2012, 09:12 PM
Thanks Shinu,

As always appreciate your support.

Sincerely

gc_0620 
Tags
ComboBox
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Share this question
or