RadComboBox LoadOnDemand SelectedValue

5 posts, 1 answers
  1. Georg
    Georg avatar
    12 posts
    Member since:
    Nov 2009

    Posted 14 Jun 2012 Link to this post

    Hello,
    i have a problem and i need some help please.

    I have this scenario:
    I have many radComboboxes inside a page and in order to make the loading time faster for the page i am using LoadOnDemand functionality.

    The thing is what on the page loads, i read a Customer fields and in the Page_Load event i populate the existing rcb (radComboBoxes) with the value from the query i get from sql so the controls will dispaly the initial existing value in there.

    This is the code i have for this (basically i manually add a new item with the initial customer value i read from SQL):
    radCtrl.Items.Clear();
    radCtrl.Items.Add(new RadComboBoxItem(rowValue, rowValue));
    radCtrl.SelectedIndex = 0;

    After that i have the ItemsRequested event where i get all the possible values for each rcb. (in this case i only show exemple for one rcb)
    protected void lstDentalGroup_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            ListItemsController ctrl = new ListItemsController();
            lstDentalGroup.DataSource = ctrl.Select_Single_Column("Value1", "DENTALGROUP");
            lstDentalGroup.DataBind();
        }

    My problem is that when i press the SAVE button inside my form, the rcb.SelectedItem.Value will always be the first item I added by default in the Page_Load event, and not the one i select in the rcb.

    Here is the HTML
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
     
    <telerik:RadAjaxManagerProxy ID="radAjaxProxy_Calls" runat="server">
        <AjaxSettings>
             
            <telerik:AjaxSetting AjaxControlID="btnSave">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="mainContrainer" LoadingPanelID="radAjaxLoadingPanel" UpdatePanelRenderMode="inline" />
                </UpdatedControls>
            </telerik:AjaxSetting>
             
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
     
    <telerik:RadCodeBlock ID="radCodeBlockMain" runat="server">
        <script type="text/javascript">
            function OnDropDownHandler(sender, eventArgs) {
                sender.requestItems("", false);
            }
        </script>
    </telerik:RadCodeBlock>
     
    <asp:Panel runat="server" ID="mainContrainer" style="width:100%; height:100%; font-size:11px;">
     
        <telerik:RadComboBox runat="server" ID="lstDentalGroup" Width="92%" Font-Size="11px" OnClientDropDownOpening="OnDropDownHandler" DataTextField="CValue" DataValueField="CValue" OnItemsRequested="lstDentalGroup_ItemsRequested" />
        <asp:Button runat="server" ID="btnSave" onclick="btnSave_Click" Text="Save Combobox Value" />
     
    </asp:Panel>
     
    </asp:Content>


    Here is the C# 
    public partial class TestTelerik : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) initialize_customerID("Boxer, Ken");
        }
     
        private void initialize_customerID(string customerID)
        {
            SQLGeneral ctrl = new SQLGeneral();
            DataTable dt = new DataTable();
            Hashtable hashFilter = new Hashtable();
            hashFilter["CustomerID"] = customerID;
            hashFilter["Deleted"] = 0;
            dt = ctrl.GetDataTable(CustomersController.customer_details, "Customers c LEFT JOIN ListItems li ON c.State = li.Value1", hashFilter);
            if (dt != null)
            {
                // populate all the textBoxes & radComboBoxes in the form within one single for cycle -> save a lot fo production time.
                for (int i = 0; i <= dt.Columns.Count - 1; i++)
                {
                    if (dt.Columns[i].DataType == typeof(System.String))
                    {
                        string columnName = dt.Columns[i].ColumnName.ToString();
                        string rowValue = dt.Rows[0][columnName].ToString().Trim();                       
     
                        // GET RADDROPDOWNBOXES
                        RadComboBox radCtrl = this.mainContrainer.FindControl("lst" + columnName) as RadComboBox;
                        if (radCtrl != null)
                        {
                            radCtrl.Items.Clear();
                            radCtrl.Items.Add(new RadComboBoxItem(rowValue, rowValue));
                            radCtrl.SelectedIndex = 0;
                        }
                    }
                }
            }
        }
     
        protected void lstDentalGroup_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            ListItemsController ctrl = new ListItemsController();
            lstDentalGroup.DataSource = ctrl.Select_Single_Column("Value1", "DENTALGROUP");
            lstDentalGroup.DataBind();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string tmpSelValue = lstDentalGroup.SelectedItem.Value;
        }
    }

    I know the rcb value are load on demand at the client side, but how i can make accessible form the server side, mentaining the LoadOnDemand functionality? The solution to get all the values on server side Page_Load event and bind them initially to all the rcb is not acceptable for me because of the amount of data to load from SQL

    Thank you for your help

  2. Georg
    Georg avatar
    12 posts
    Member since:
    Nov 2009

    Posted 19 Jun 2012 Link to this post

    Is there a way, please, to get an answer to this post ?
  3. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 19 Jun 2012 Link to this post

    Hello George Peiov,

    RadComboBox items populated via Load On Demand are not accessible at server-side - please find more details about this topic here.
    Please use the RadComboBox SelectedValue and Text properties instead.

    Regards,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  4. Georg
    Georg avatar
    12 posts
    Member since:
    Nov 2009

    Posted 19 Jun 2012 Link to this post

    Hello,
    thank you for your answer, but can you please take a better look at my scenario ? I already tryed before postign this the "SelectedValue" and the same result.

    Please take a look at the html i provided as i'm not using explicit LoadOnDemand="true" because i dont want the control to allow custom text input, but instead i'm using the javascript work around provided in http://www.telerik.com/help/aspnet-ajax/combobox-cannot-disable-allowcustomtext-load-on-demand.html.

    So let me make it clearer by adding a different code that emulate the same problem, but easier to follow:
    public partial class TestTelerik : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && !Page.IsCallback) initialize_customerID();
        }
     
        private void initialize_customerID()
        {
            lstDentalGroup.Items.Clear();
            lstDentalGroup.Items.Add(new RadComboBoxItem("1", "1"));
        }
     
        protected void lstDentalGroup_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            lstDentalGroup.Items.Clear();
            lstDentalGroup.Items.Add(new RadComboBoxItem("0", "0"));
            lstDentalGroup.Items.Add(new RadComboBoxItem("1", "1"));
            lstDentalGroup.Items.Add(new RadComboBoxItem("2", "2"));
            lstDentalGroup.Items.Add(new RadComboBoxItem("3", "3"));
            lstDentalGroup.Items.Add(new RadComboBoxItem("4", "4"));
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string tmpSelValue = lstDentalGroup.SelectedValue; // when i select "3" in the list it returns initial value "1"
            string tmpSelText = lstDentalGroup.Text; // when i select text "3" in the list, it returns correct text "3"
        }
    }

    So please notice these comments:
    SelectedValue - when i select "3" in the list it returns wrong initial value i provided in initialization method ("1")
    Text - when i select text "3" in the list, it returns correct text "3", but after the save event ends, the RCB returns to the default text "1"..so is not persistent.
    Still...i dont need the TEXT, but the VALUE, so i need to correctly get the SelectedValue.
    Any thoughts on this please ?
  5. Answer
    Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 22 Jun 2012 Link to this post

    Hello George,

    You can try disabling the RadComboBox ViewState:
    <telerik:RadComboBox ID="lstDentalGroup" runat="server" 
        EnableViewState="false"
        EnableLoadOnDemand="true" 
        OnItemsRequested="lstDentalGroup_ItemsRequested">
    </telerik:RadComboBox>
    <asp:Button runat="server" ID="btnSave" OnClick="btnSave_Click" Text="Save" />
    <asp:Label runat="server" ID="lblTest"></asp:Label>

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack && !Page.IsCallback)
            initialize_customerID();
    }
     
    private void initialize_customerID()
    {
     
        lstDentalGroup.Items.Clear();
        lstDentalGroup.Items.Add(new RadComboBoxItem("1", "1"));
    }
     
    protected void lstDentalGroup_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        lstDentalGroup.Items.Clear();
        lstDentalGroup.Items.Add(new RadComboBoxItem("0", "0"));
        lstDentalGroup.Items.Add(new RadComboBoxItem("1", "1"));
        lstDentalGroup.Items.Add(new RadComboBoxItem("2", "2"));
        lstDentalGroup.Items.Add(new RadComboBoxItem("3", "3"));
        lstDentalGroup.Items.Add(new RadComboBoxItem("4", "4"));
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string tmpSelValue = lstDentalGroup.SelectedValue;
        lblTest.Text = "text: " + lstDentalGroup.Text + " value:" + lstDentalGroup.SelectedValue;
    }

    Regards,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top