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

[Solved] Mutiple Field up Via Combobox

7 Answers 135 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
bradley baker
Top achievements
Rank 1
bradley baker asked on 22 Dec 2009, 03:59 PM
I have a combo box that has a list of Part Numbers and its in template so it shows:
 ______________________________
|Part Number: 1234-1234-1234-1234    |
|Facility: NY Facility                                |
--------------------------------------------------
|Part Number: 1234-1234-1234-1234    |
|Facility: PA Facility                                |
--------------------------------------------------
|Part Number: 1234-1234-1234-1234    |
|Facility: NJ Facility                                 |
--------------------------------------------------

I have it setup so the onselectedindexchanged will put the PN into a TextBox, but I would also like to put the Facility into a TextBox also.  How would I achieve this?  I cant load the entire dataset as it has >100k records and causes far too much overhead.  (I have it setup to load on demand and only sugest PN after 4 characters have been entered)

    Protected Sub RadComboBox3_SelectedIndexChanged(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
        Dim editedItem As GridEditableItem = CType(CType(o, RadComboBox).NamingContainer, GridEditableItem)  
        Dim PNCombo As RadComboBox = CType(editedItem.FindControl("RadComboBox3"), RadComboBox)  
        
        Dim PNBOX As TextBox = CType(editedItem.FindControl("PN"), TextBox)  
        Dim FACBOX As TextBox = CType(editedItem.FindControl("FAC"), TextBox)  
 
 
        PNBOX.Text = PNCombo.SelectedValue  
        FACBOX.Text = ????????
 
    End Sub 


7 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 23 Dec 2009, 01:22 PM
Hello bradley baker,

If you store the Facility value in a Custom Attribute for each Item you could do the following:
  1. Put a HiddenField next to the RadComboBox with a recognizable ID.
  2. Handle the client-side SelectedIndexChanging event of the RCB in this way:
    function onSelectedIndexChanging(sender, eventArgs) {
        $get("RadComboBox1SelectedFacility").value = eventArgs.get_item().get_attributes().getAttribute("Facility");
    }
  3. Then on the server side you could get the Facility value from the HiddenField control's Value property.
I hope this helps.

All the best,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
bradley baker
Top achievements
Rank 1
answered on 28 Dec 2009, 03:44 PM
My combobox is dynamic because of the size of the datasource.  How do I modify this to work with custom attributes.
I looked at this page but didnt seem to have an example for my solution:
http://www.telerik.com/help/aspnet-ajax/combo_customattributes.html

    Protected Sub PN_ItemsRequested(ByVal o As ObjectByVal e As RadComboBoxItemsRequestedEventArgs)  
        Dim combo As RadComboBox = DirectCast(o, RadComboBox)  
        ItemNoDropDownSQL.SelectCommand = "SELECT [ICPROD], [ICFAC] FROM [CIC] WHERE [ICPROD] Like '" + e.Text + "%'  ORDER BY [ICPROD] ASC" 
        combo.DataSource = ItemNoDropDownSQL  
        combo.DataTextField = "ICPROD" 
        combo.DataValueField = "ICPROD" 
        combo.DataBind()  
    End Sub 
<tr> 
                    <td> 
                        Item No:</td> 
                    <td> 
                            <telerik:RadComboBox ID="RadComboBox3" Runat="server" AllowCustomText="True" CausesValidation="false" 
                            EnableLoadOnDemand="True" onitemsrequested="PN_ItemsRequested" AutoPostBack="true" 
                            onclientitemsrequesting="StopRequesting" Width="250px" onselectedindexchanged="RadComboBox3_SelectedIndexChanged" 
                            Text='<%# DataBinder.Eval(Container.DataItem,"zpn_pn") %>' OnClientSelectedIndexChanged="onSelectedIndexChanging">  
                            <ItemTemplate> 
                                PN: <%#Eval("ICPROD")%> 
                                <br /> 
                                Fac: <%#Eval("ICFAC")%> 
                                <hr /> 
                            </ItemTemplate> 
                            </telerik:RadComboBox> 
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"   
                            ErrorMessage="Required" ControlToValidate="RadComboBox3"></asp:RequiredFieldValidator> 
                        <asp:TextBox ID="PN" runat="server" Text='<%# Bind("zpn_pn") %>'   
                            Visible="True"></asp:TextBox>   
                        <asp:TextBox ID="FAC" runat="server" Text='<%# Bind("zpn_fac") %>'   
                            Visible="True"></asp:TextBox>      
 
                    </td> 
                </tr> 
0
Veselin Vasilev
Telerik team
answered on 29 Dec 2009, 10:12 AM
Hi bradley baker,

Actually you cannot use custom Attributes in load on demand scenario. You can use only the Text and the SelectedValue properties as described here. That is why you need to follow the Simon's advice.
You can directly set the text of the textbox in OnClientSelectedIndexChanged event:

function onSelectedIndexChanged(sender, e) {
   var txt = $get("<%= FAC.ClientID %>");
   txt.value = e.get_item().get_attributes().getAttribute("Facility");
}


Regards,
Veskoni
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
bradley baker
Top achievements
Rank 1
answered on 29 Dec 2009, 04:41 PM
If I can not use custom attributes then why in the examples do you keep telling me to use attributes?  What am I not understanding here?  I dont want to load a combobox with >100k part numbers this is why I have it setup with the load on demand and will only list part numbers after 4 numbers have been entered, this way the client doesnt slow down and their selection is prefiltered already (List size goes to < 250 once you enter 4 numbers).  So is there still a way for me to get the facility?

This gives me an error: Compiler Error Message: BC30451: Name 'FAC' is not declared.
function onSelectedIndexChanged(sender, e) {  
   var txt = $get("<%= FAC.ClientID %>");  
   txt.value = e.get_item().get_attributes().getAttribute("Facility");  
}  
 

0
Veselin Vasilev
Telerik team
answered on 04 Jan 2010, 09:32 AM
Hello bradley baker,

I apologize for the misunderstanding. The custom attributes in load on demand scenario can be used on the client only (via the javascript methods of the RadComboBoxItems). They cannot be used in the server code.

Please change the method as follows:

function onSelectedIndexChanged(sender, e) {
   var txtID = sender.get_id().replace("RadComboBox3", "FAC");
   var txt = $get(txtID);
   txt.value = e.get_item().get_attributes().getAttribute("Facility");
}


All the best,
Veskoni
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
bradley baker
Top achievements
Rank 1
answered on 04 Jan 2010, 05:32 PM
Okay so I put that code in and there is no error, but there is also no content populating the text box.  Doesnt there need to be a "attribute" assigned to the combobox first before I can select it?

How do I assign the "Facility" attribute to the combobox via load on demand?  (You stated below it wasnt possible)

************
Further checking is showing that there are now attributes defined.   (If i make the txt.value="test" then test is populated into the FAC box)
This is the load on demand script that its using.

 

Protected Sub PN_ItemsRequested(ByVal o As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)

 

 

Dim combo As RadComboBox = DirectCast(o, RadComboBox)

 

ItemNoDropDownSQL.SelectCommand =

"SELECT [ICPROD], [ICFAC] FROM [CIC] WHERE [ICPROD] Like '" + e.Text + "%' ORDER BY [ICPROD] ASC"

 

combo.DataSource = ItemNoDropDownSQL

combo.DataTextField =

"ICPROD"

 

combo.DataValueField =

"ICPROD"

 

combo.Attributes(

"Facility") = "ICFAC"

 

combo.DataBind()

 

End Sub

 

0
Simon
Telerik team
answered on 05 Jan 2010, 01:39 PM
Hi bradley baker,

You could add the Custom Attribute in your case by handling the server-side ItemDataBound event of the RadComboBox in this way:

Protected Sub RadComboBox3_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs)
    e.Item.Attributes.Add("Facility", DirectCast(e.Item.DataItem, DataRowView)("ICFAC").ToString)
End Sub

After that, using the approach from the second reply in this thread should get you to where you were headed in the first place.

Please let me know if you have any additional questions.

Kind regards,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ComboBox
Asked by
bradley baker
Top achievements
Rank 1
Answers by
Simon
Telerik team
bradley baker
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or