Update panel Problem

3 posts, 0 answers
  1. Atul
    Atul avatar
    11 posts
    Member since:
    Jan 2012

    Posted 18 Jan 2012 Link to this post

    I Have two combobox inside update panel... second is populating based on selection of first on onselectedindex event ,... but 1st time I Change index of first combo box it is ok.. but second time is not populating according to first combo box value..........
    plz help?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Jan 2012 Link to this post

    Hello,

    Try the following code snippet.
    ASPX:
    <asp:UpdatePanel ID="panel1" runat="server">
       <ContentTemplate>
        <telerik:RadComboBox ID="combo1" runat="server" OnItemsRequested="combo1_ItemsRequested" OnClientSelectedIndexChanging="loadcombo1">
        </telerik:RadComboBox>
        <telerik:RadComboBox ID="combo2" runat="server" OnItemsRequested="combo2_ItemsRequested" OnClientItemsRequested="ItemsLoaded">
        </telerik:RadComboBox>
      </ContentTemplate>
    </asp:UpdatePanel>

    C#:
    protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               LoadCmbo1();
           }
           else
           {
               LoadCmbo2(combo1.SelectedValue);
           }
       }
       protected void LoadCmbo1()
       {
           SqlConnection connection = new SqlConnection(
           ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
     
           SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Customers", connection);
           DataTable dt = new DataTable();
           adapter.Fill(dt);
     
           combo1.DataTextField = "CustomerID";
           combo1.DataValueField = "CustomerID";
           combo1.DataSource = dt;
           combo1.DataBind();
           combo1.Items.Insert(0, new RadComboBoxItem("- Select -"));
       }
       protected void LoadCmbo2(string CustomerID)
       {
           SqlConnection connection = new SqlConnection(
           ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Orders WHERE CustomerID=@CustomerID", connection);
           adapter.SelectCommand.Parameters.AddWithValue("@CustomerID", CustomerID);
           DataTable dt = new DataTable();
           adapter.Fill(dt);
           combo2.DataTextField = "OrderID";
           combo2.DataValueField = "OrderID";
           combo2.DataSource = dt;
           combo2.DataBind();
       }
       protected void combo1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
       {
           LoadCmbo1();
       }
       protected void combo2_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
       {
           LoadCmbo2(e.Text);
       }

    JS:
    <script type="text/javascript">
       var Combo1;
      function pageLoad()
       {
            combo2 = $find("<%= combo2.ClientID %>");
       }
     function loadcombo1(sender, args)
       {
            var item = args.get_item();
            combo2.set_text("Loading...");
            if (item.get_index() > 0)
           {
                combo2.requestItems(item.get_value(), false);
           }
       else
        {
                combo2.set_text(" ");
                combo2.clearItems();
        }
      }
     function ItemsLoaded(sender, eventArgs)
     {
            if (sender.get_items().get_count() > 0)
        {
                sender.set_text(sender.get_items().getItem(0).get_text());
                sender.get_items().getItem(0).highlight();
        }
            sender.showDropDown();
      }
    </script>

    Thanks,
    Princy.
  3. Mahesh
    Mahesh avatar
    6 posts
    Member since:
    Jan 2013

    Posted 30 Jan 2013 Link to this post



    use telerik radajaxpanel instead of asp updatepanel ....
Back to Top