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

Update panel Problem

2 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Atul
Top achievements
Rank 1
Atul asked on 18 Jan 2012, 10:11 AM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2012, 01:14 PM
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.
0
Mahesh
Top achievements
Rank 1
answered on 30 Jan 2013, 11:34 AM


use telerik radajaxpanel instead of asp updatepanel ....
Tags
General Discussions
Asked by
Atul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mahesh
Top achievements
Rank 1
Share this question
or