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

Third value

3 Answers 90 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
El
Top achievements
Rank 1
El asked on 22 Jul 2009, 02:01 PM
I need one more value to be added but i am not sure that ComboBox supports that.

e.g. i have the following columns in the DB:

ID, Title, Price

I need to display the Title but to get the selected ID and Price.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 22 Jul 2009, 02:39 PM
Hi,

You can add custom Attribute of RadComboBoxItem in order to store the 'Price', so that you can retrieve the value in SelectedIndexChanged event.

C#:
 
protected void RadComboBox1_ItemDataBound(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e)   
{   
    DataRowView dataSourceRow = (DataRowView)e.Item.DataItem;   
    //set custom attributes from the datasource:   
    e.Item.Attributes["Price"] = dataSourceRow["Price"].ToString();   
}   
protected void RadComboBox1_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)   
{  
    String ID = e.Text;   
    String Price = RadComboBox1.SelectedItem.Attributes["Price"]; 
}   

-Shinu.
0
Emi
Top achievements
Rank 1
answered on 04 Oct 2011, 09:31 AM
I try using this but change it a little bit since I'm using Vb.net but failed.. It keep saying that "Object reference not set to an instance of an object.".

Is there something I'm missing or need to add?
0
Shinu
Top achievements
Rank 1
answered on 04 Oct 2011, 10:37 AM
Hello Emi,

Here is the VB version of the code.
VB:
Protected Sub RadComboBox1_ItemDataBound(sender As Object, e As Telerik.Web.UI.RadComboBoxItemEventArgs)
    Dim dataSourceRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
    e.Item.Attributes("Price") = dataSourceRow("Price").ToString()
End Sub
 
Protected Sub RadComboBox1_SelectedIndexChanged(o As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
    Dim ID As [String] = e.Text
    Dim Price As [String] = RadComboBox1.SelectedItem.Attributes("Price")
End Sub

Thanks,
Shinu.
Tags
ComboBox
Asked by
El
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Emi
Top achievements
Rank 1
Share this question
or