Hi,I have created a button to simulate clicking the arrow on a combobox.
Basically I hide the combobox and call the javascript to triggers the dropdown behavior of the combobox when a user clicks on the button.
The user will be able to select an item from the dropdown and then the code-behind will populate the selected address into the textboxes accordingly.Everything works ok up to this point. The problem starts after the postback, data in the dropdown list is gone.
I found a few posts on the forum which says we need to load the data on each post back or in the ItemsRequested event but that didn't work for me.
I must be missing something obvious, but just can't spot it. Please help~
javascript :
Since the combobox is in a user control, I load the javascript using ScriptManager.
code-behind:
protected void Page_Load(object sender, EventArgs e){ // Load script dynamically for user control // Refer to : http://www.telerik.com/forums/javascript-not-loaded-when-loading-user-control-dynamically-in-an-ajax-request StringBuilder script = new StringBuilder(); script.Append("function ShowDropDownFunction() {"); script.Append("var combo = $find('" + RadLogixBuildingComboBox.ClientID + "');"); script.Append("combo.showDropDown(); }"); ScriptManager.RegisterStartupScript(Page, typeof(Page), "script1", script.ToString(), true); SALTLeadDetailsBLL _detailBLL = new SALTLeadDetailsBLL(); SALTLeadDetailsDAL.sbms_bldgDataTable dt = _detailBLL.GetLogixBuildings(SalesID); RadLogixBuildingComboBox.DataSource = dt; RadLogixBuildingComboBox.DataBind();}protected void RadLogixBuildingComboBox_ItemDataBound(object sender, RadComboBoxItemEventArgs e){ DataRowView dataItem = (DataRowView)e.Item.DataItem; e.Item.Text = dataItem["bldgstreet1"].ToString().Trim() + "; " + dataItem["bldgcity"].ToString().Trim() + "; " + dataItem["bldgstate"].ToString().Trim() + "; " + dataItem["bldgzip"].ToString().Trim() + "; " + dataItem["market"].ToString().Trim(); e.Item.Value = dataItem["bldgstreet1"].ToString().Trim() + "; " + dataItem["bldgcity"].ToString().Trim() + "; " + dataItem["bldgstate"].ToString().Trim() + "; " + dataItem["bldgzip"].ToString().Trim() + "; " + dataItem["market"].ToString().Trim();}protected void RadLogixBuildingComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e){ // When loadondemand is turned on, SelectedItem is not available : http://www.telerik.com/forums/combobox-selecteditem-getting-null-even-when-it-is-selected-from-the-list // Use e.item.text and e.item.value in ItemDataBound event String selectedItemValues = RadLogixBuildingComboBox.SelectedValue; List<string> itemValues = selectedItemValues.Split(';').ToList(); string[] zipCode = itemValues[3].Trim().Split('-'); string zip = zipCode[0].ToString().Trim(); string zipExt = zipCode[1].ToString().Trim(); Address1TextBox.Text = itemValues[0].ToString().Trim(); CityTextBox.Text = itemValues[1].ToString().Trim(); StateTextBox.Text = itemValues[2].ToString().Trim(); ZipTextBox.Text = zip; ZipExtTextBox.Text = zipExt; RadMarketComboBox.SelectedValue = itemValues[4].ToString().Trim();}protected void RadLogixBuildingComboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e){ SALTLeadDetailsBLL _detailBLL = new SALTLeadDetailsBLL(); SALTLeadDetailsDAL.sbms_bldgDataTable dt = _detailBLL.GetLogixBuildings(SalesID); RadLogixBuildingComboBox.DataSource = dt; RadLogixBuildingComboBox.DataBind();}ascx :
<telerik:RadButton ID="LogixBuildingImageButton" AutoPostBack="false" runat="server" Image-ImageUrl="~/images/building16.png" ToolTip="Logix Buildings" Width="16px" Height="16px" OnClientClicked="ShowDropDownFunction" /><telerik:RadComboBox ID="RadLogixBuildingComboBox" runat="server" AutoPostBack="true" MarkFirstMatch="false" ItemsPerRequest="5" ShowMoreResultsBox="true" EnableAutomaticLoadOnDemand="true" EnableVirtualScrolling="true" DropDownAutoWidth="Disabled" DropDownWidth="700px" Width="0" Height="150px" HighlightTemplatedItems="true" EnableScreenBoundaryDetection="true" OnItemDataBound="RadLogixBuildingComboBox_ItemDataBound" OnSelectedIndexChanged="RadLogixBuildingComboBox_SelectedIndexChanged" OnItemsRequested="RadLogixBuildingComboBox_ItemsRequested" > <HeaderTemplate> <table> <tr> <td class="logixbuildingcol1">Building Street</td> <td class="logixbuildingcol2">City</td> <td class="logixbuildingcol3">State</td> <td class="logixbuildingcol4">Zip</td> <td class="logixbuildingcol5">Status</td> <td class="logixbuildingcol6">Address Type</td> </tr> </table> </HeaderTemplate> <ItemTemplate> <table> <tr> <td class="logixbuildingcol1"><%# DataBinder.Eval(Container.DataItem, "bldgstreet1") %> </td> <td class="logixbuildingcol2"><%# DataBinder.Eval(Container.DataItem, "bldgcity") %></td> <td class="logixbuildingcol3"><%# DataBinder.Eval(Container.DataItem, "bldgstate") %></td> <td class="logixbuildingcol4"><%# DataBinder.Eval(Container.DataItem, "bldgzip") %></td> <td class="logixbuildingcol5"><%# DataBinder.Eval(Container.DataItem, "buildingStatus") %></td> <td class="logixbuildingcol6"><%# DataBinder.Eval(Container.DataItem, "addressTypeDesc") %></td> </tr> </table> </ItemTemplate> <FooterTemplate> <table> <tr> <td class="logixbuildingcol1"><telerik:RadButton ID="RadCloseButton" runat="server" AutoPostBack="false" Text="Close" Icon-PrimaryIconUrl="~/images/exit_16x16.png" OnClientClicking="HideDropDownFunction()" /></td> </tr> </table> </FooterTemplate></telerik:RadComboBox>Thank you,
Helen