getting combobox selected item value on aspx page

5 posts, 0 answers
  1. Tarang
    Tarang avatar
    11 posts
    Member since:
    Oct 2011

    Posted 17 Jan 2012 Link to this post


    Hi ,
    I have a user control having a radCombobox Now I want to use the selectedvalue from this dropdown on an aspx page where I want to use this selected value as an input parameter to a function which fills a normal dropdown list on this page based on what the value was selected.
    I have called this function in the onitemsrequested event of the normal dropdown.Now the problem is that it always takes null.
    As a result the dropdown is blank irrespective of what I choose.

    Please let me know how to achieve this,if this is not possible by onitemsrequested event,I do not want to create a new user control having both the things on one page.Instead i want the page to call usercontrol value.
    I tried using public property concept.it does not work.

    Here is the event definition.

      [
    protected void ddlCommodity_itemRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
             string exchange1 = ExchangeType.Exchange;                               
             DataSet CommodityCodes = service.GetCommodities(exchange1);

            ddlCommodity.DataSource = CommodityCodes.Tables[0];
            ddlCommodity.DataTextField = "'ALL'";
            ddlCommodity.DataValueField = "'ALL'";
            ddlCommodity.DataBind();
        }


    the property is
    public string Exchange
        {
            get { return ddlExchangeType.SelectedValue;}
            set { ddlExchangeType.SelectedValue = value; }
        }
    ]

  2. Abhishek
    Abhishek avatar
    45 posts
    Member since:
    Jul 2012

    Posted 17 Jan 2012 Link to this post

    Hello Tarang,

    I have tried one example for your issue. i am sending you some test code please have look over it.
    Radcombo UserControl :
     
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RadComboBox.ascx.cs"
        Inherits="LearnTelerikControls.UserControls.RadComboBox" %>
    <telerik:RadComboBox ID="rcbBusinessUnits" runat="server" EnableEmbeddedSkins="false"
        ForeColor="Blue" Font-Underline="true" Width="400px" Font-Bold="true" AutoPostBack="true">   
        <Items>
            <telerik:RadComboBoxItem Text="--Select--" Value="1" />
            <telerik:RadComboBoxItem Text="Item_1" Value="2" />
            <telerik:RadComboBoxItem Text="Item_2" Value="3" />
            <telerik:RadComboBoxItem Text="Item_3" Value="4" />
            <telerik:RadComboBoxItem Text="Item_4" Value="5" />
        </Items>
    </telerik:RadComboBox>
    Properties in(.cs) of User Control:
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    namespace LearnTelerikControls.UserControls
    {
        public partial class RadComboBox : System.Web.UI.UserControl
        {
            public string Exchange
            {
                get { return rcbBusinessUnits.SelectedValue; }
                set { rcbBusinessUnits.SelectedValue = value; }
            }
     
            protected void Page_Load(object sender, EventArgs e)
            {           
            }
     
     
        }
    }


    Now Aspx Code:
    <%@ Page Title="" Language="C#" MasterPageFile="~/MainStarter.Master" AutoEventWireup="true"
        CodeBehind="NormalDropdown.aspx.cs" Inherits="LearnTelerikControls.RadCombo.NormalDropdown" %>
     
    <%@ Register TagPrefix="RadComboBoxUserControl" TagName="RadComboBoxUserControl"
        Src="~/UserControls/RadComboBox.ascx" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="BodyContainer" runat="server">
        <table>
            <tr>
                <td>
                    <RadComboBoxUserControl:RadComboBoxUserControl ID="rcbUserControl" runat="server" />
                </td>
            </tr>
            <tr>
                <td>
                    New Combo:
                </td>
                <td>
                    <telerik:RadComboBox ID="ddlCommodity" runat="server" EmptyMessage="Select a Values"
                        ShowMoreResultsBox="true" EnableLoadOnDemand="True" OnItemsRequested="ddlCommodity_itemRequested">
                    </telerik:RadComboBox>
                </td>
            </tr>
        </table>
    </asp:Content>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using Telerik.Web.UI;
     
    namespace LearnTelerikControls.RadCombo
    {
        public partial class NormalDropdown : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {                                  
            }
     
            protected void ddlCommodity_itemRequested(object o, RadComboBoxItemsRequestedEventArgs e)
            {           
                BindCombo();
                ddlCommodity.SelectedValue = rcbUserControl.Exchange;
            }
     
     
            private void BindCombo()
            {
                DataTable dt = GetDataTable();
     
                ddlCommodity.DataSource = dt;
                ddlCommodity.DataTextField = "FirstName";
                ddlCommodity.DataValueField = "ID";
                ddlCommodity.DataBind();
            }
     
            private DataTable GetDataTable()
            {
                DataTable dt = new DataTable("TestTable");
                dt.Columns.Add("ID");
                dt.Columns.Add("FirstName");
     
                dt.Rows.Add(1, "Abhishek");
                dt.Rows.Add(2, "Adiya");
                dt.Rows.Add(3, "ABC");
                dt.Rows.Add(4, "PQR");
                dt.Rows.Add(5, "XYZ");
                return dt;
            }
        }
    }

     Please try this with your code. Let me know if any query.

    Thanks,
    Abhishek K
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tarang
    Tarang avatar
    11 posts
    Member since:
    Oct 2011

    Posted 17 Jan 2012 Link to this post

    Hi,

    Thanks for the reply.
    Actually I wanted to pass the usercontrol selected value as a function parameter.for eg.your GetDataTable()parameter function takes rcbUserControl.Exchange as input parameter.Based on that the normalDropDown is to be populated.

    Please help me how to achieve this.

    Regards,
    Tarang
  5. Tarang
    Tarang avatar
    11 posts
    Member since:
    Oct 2011

    Posted 18 Jan 2012 Link to this post

    Hi,the problem got solved.

    All i did was in the main page I declared a radcombobox type variable and assigned the usercontrol to it with help of find control.

    protected

     

    void commodity_ItemRequested(object o, RadComboBoxItemsRequestedEventArgs e)

     

    {  

    RadComboBox exchange1 = (RadComboBox)ExchangeType.FindControl("ddlExchangeType");  // I created this variable

     string ExchangeList = exchange1.SelectedValue;                                              //all properties of usecontrol can be accessed thru here

     DataSet CommodityCodes = service.GetCommodities(ExchangeList);

    ddlCommodity.DataSource = CommodityCodes.Tables[0];

    ddlCommodity.DataTextField =

    "'ALL'";
    ddlCommodity.DataValueField =
    "'ALL'";
    ddlCommodity.DataBind();

     

    }

    It might be helpful if any one facing similar problem .There posting it.


    Thanks
    Tarang

  6. Abhishek
    Abhishek avatar
    45 posts
    Member since:
    Jul 2012

    Posted 18 Jan 2012 Link to this post

    Hello Tarang,

    I have updated the code according to your requirement please have one look.

    NormalDropdown.aspx
     
     
    <%@ Page Title="" Language="C#" MasterPageFile="~/MainStarter.Master" AutoEventWireup="true"
        CodeBehind="NormalDropdown.aspx.cs" Inherits="LearnTelerikControls.RadCombo.NormalDropdown" %>
     
    <%@ Register TagPrefix="RadComboBoxUserControl" TagName="RadComboBoxUserControl"
        Src="~/UserControls/RadComboBox.ascx" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="BodyContainer" runat="server">
        <table>
            <tr>
                <td>
                    <RadComboBoxUserControl:RadComboBoxUserControl ID="rcbUserControl" runat="server" />
                </td>
            </tr>
            <tr>           
                <td>
                    <telerik:RadComboBox ID="ddlCommodity" runat="server" EmptyMessage="Select a Values" Height=""
                        ShowMoreResultsBox="true" EnableLoadOnDemand="True" OnItemsRequested="ddlCommodity_itemRequested">
                    </telerik:RadComboBox>
                     
                </td>
            </tr>
        </table>
    </asp:Content>




    ---------------------------------------------------------------------------------------------------------
    NormalDropdown.cs
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using Telerik.Web.UI;
     
    namespace LearnTelerikControls.RadCombo
    {
        public partial class NormalDropdown : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {              
                }
            }
     
            protected void ddlCommodity_itemRequested(object o, RadComboBoxItemsRequestedEventArgs e)
            {           
                BindCombo();           
            }
     
     
            protected void BindCombo()
            {
                DataTable dt = GetDataTable(rcbUserControl.Exchange);           
                ddlCommodity.DataSource = dt;
                ddlCommodity.DataTextField = "Name";
                ddlCommodity.DataValueField = "ID";
                ddlCommodity.DataBind();
            }
     
           
     
            protected DataTable GetDataTable(string TypeID)
            {
                DataTable table = GetNewTable();
                table.Rows.Add(1, "Winter", null);
                table.Rows.Add(2, "Summer", null);
     
                table.Rows.Add(3, "Biathlon", 1);
                table.Rows.Add(4, "Figure skating", 1);
                table.Rows.Add(5, "Alpine skiing", 1);
                table.Rows.Add(6, "Ski jumping", 1);
     
                table.Rows.Add(7, "Basketball", 2);
                table.Rows.Add(8, "Boxing", 2);
                table.Rows.Add(9, "Swimming", 2);
                table.Rows.Add(10, "Volleyball", 2);
                table.Rows.Add(11, "Wrestling", 2);
                table.Rows.Add(12, "Cycling", 2);
     
                //filter the values from the datatable
                DataTable FilteredTable = GetNewTable();
                foreach (DataRow Item in table.Rows)
                {
                    DataRow Row = FilteredTable.NewRow();
                        if(TypeID.Equals(Item[2].ToString()))
                        {
                            Row[0] = Item[0].ToString();
                            Row[1] = Item[1].ToString();
                            Row[2] = Item[2].ToString();
                            FilteredTable.Rows.Add(Row);
                        }
                }
     
                return FilteredTable;
            }
     
            protected DataTable GetNewTable()
            {
                DataTable table = new DataTable();
                table.Columns.Add("ID", typeof(int));
                table.Columns.Add("Name");
                table.Columns.Add("TypeID", typeof(int));
                return table;
            }
        }
    }


    RadComboBox.ascx :
     
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RadComboBox.ascx.cs"
        Inherits="LearnTelerikControls.UserControls.RadComboBox" %>
    <telerik:RadComboBox ID="rcbBusinessUnits" runat="server" EnableEmbeddedSkins="false"
        ForeColor="Blue" Font-Underline="true" Width="400px" Font-Bold="true" AutoPostBack="true">   
        <Items>
            <telerik:RadComboBoxItem Text="--Select--" Value="0" />
            <telerik:RadComboBoxItem Text="Item_1" Value="1" />
            <telerik:RadComboBoxItem Text="Item_2" Value="2" />       
        </Items>
    </telerik:RadComboBox>

    No Changes in the RadComboBox.cs
    Let me know if any issue. I think you got the solution for your query.

    Thanks,
    Abhishek K
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017