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

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

1 Answer 103 Views
Window
This is a migrated thread and some comments may be shown as answers.
Dorababu
Top achievements
Rank 1
Dorababu asked on 21 Jun 2012, 10:38 AM
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.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jun 2012, 12:13 PM
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.
Tags
Window
Asked by
Dorababu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or