How to disable combo box items that are in RadWindow on button click from server side

2 posts, 0 answers
  1. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 21 Jun 2012 Link to this post

    I would like to disable some items in combo box when I click on button . What I am doing is on button click  I will show a rad window with a combo box , when that was loaded I would like to disable some items

    My design is as follows

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="radWindow.aspx.cs" Inherits="radWindow" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="radScript" runat="server">
        </telerik:RadScriptManager>
        <div>
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Behavior="Default"
                InitialBehavior="None">
                <Windows>
                    <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Default" InitialBehaviors="None"
                        OpenerElementID="btn" Width="650" Height="480" VisibleOnPageLoad="false">
                        <ContentTemplate>
                            <telerik:RadComboBox ID="rdcmb" runat="server">
                                <Items>
                                    <telerik:RadComboBoxItem Text="One" Value="One" />
                                    <telerik:RadComboBoxItem Text="Two" Value="Two" />
                                    <telerik:RadComboBoxItem Text="Three" Value="Three" />
                                    <telerik:RadComboBoxItem Text="Four" Value="Four" />
                                </Items>
                            </telerik:RadComboBox>
                            <telerik:RadTextBox ID="rdText" runat="server">
                            </telerik:RadTextBox>
                            <telerik:RadButton ID="radbtn" runat="server" Text="Save" OnClick="radbtn_Click">
                            </telerik:RadButton>
                        </ContentTemplate>
                    </telerik:RadWindow>
                </Windows>
            </telerik:RadWindowManager>
            <asp:Button ID="btn" runat="server" OnClick="btn_Click" Text="Click" />
        </div>
        </form>
    </body>
    </html>

    My code on button click is as follows

    protected void btn_Click(object sender, EventArgs e)
        {
            foreach (RadComboBoxItem item in rdcmb.Items)
            {
                if (item.Text == "One" || item.Text == "Two")
                {
                    item.Remove();
                }
            }
            RadWindowManager1.Windows[0].VisibleOnPageLoad = true;
        }

    But I am unable to achieve the required.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Jun 2012 Link to this post

    Hi,

    Using OpenerElementID in complex scenarios is not recommended. In addition when you use OpenerElementID set to some button, you will not be able to use that button's click on the server. Here is the sample code that I tried which worked as expected.
    C#:
    protected void btn_Click(object sender, EventArgs e)
    {
      foreach (RadComboBoxItem item in rdcmb.Items)
     {
        if (item.Text == "One" || item.Text == "Two")
        {
             item.Enabled = false;
        }
     }
    RadWindowManager1.Windows[0].VisibleOnPageLoad = true;
    }

    Thanks,
    Shinu.
Back to Top