Third value

4 posts, 1 answers
  1. El
    El avatar
    130 posts
    Member since:
    Dec 2008

    Posted 22 Jul 2009 Link to this post

    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.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Jul 2009 Link to this post

    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.
  3. Emi
    Emi avatar
    8 posts
    Member since:
    Feb 2011

    Posted 04 Oct 2011 Link to this post

    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?
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Oct 2011 Link to this post

    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.
Back to Top