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

[Solved] Adding objects to Combo Box

1 Answer 145 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Carl
Top achievements
Rank 1
Carl asked on 22 Jan 2010, 07:30 PM
I have a class that contains information about reports:

public

 

class ReportRequest

 

{

 

 public int ReportID { get; set; }

 

 

 public string ReportName { get; set; }

 

 

 public int Days { get; set; }

 

 

 public ReportRequest(int reportID, string reportName, int days)

 

 {

 

  this.ReportID = reportID;

 

 

  this.ReportName = reportName;

 

 

  this.Days = days;

 

 }

}

and I want to load a collection of these objects into a combo box like this:

List<ReportRequest> reports = new List<ReportRequest>();

 

reports.Add(

new ReportRequest(1, "Report 1", 10));

 

reports.Add(

new ReportRequest(2, "Report 2", 20));

 

reports.Add(

new ReportRequest(3, "Report 3", 30));

 

reports.Add(

new ReportRequest(4, "Report 4", 40));

 

RadComboBox1.DataValueField =

"ReportID";

 

RadComboBox1.DataTextField =

"ReportName";

 

RadComboBox1.DataSource = reports;

RadComboBox1.DataBind();

I only want the report name to show but when a user makes a selection I'd like to get the Days property as well. Its not truly a multi-column combo box as only 1 column will show to the user. I also can't seen to add anything other than a RadComboBoxItem to the Items collection of the combo box.

How can I accomplish this?

Thanks

Carl

1 Answer, 1 is accepted

Sort by
0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 23 Jan 2010, 05:52 PM
I had a ticket in about doing something like this once :)
(Veselin Vasilev's idea )

Try adding an attribute to the ComboBoxItem to represent Days...and then on the clientside selected event, modify the text to show the value (append the days to it)

item.Attributes["days"] = dayvalue.ToString(); 

Clientside
<script type="text/javascript"
    function onClientSelectedIndexChangedHandler(sender, e) { 
        var item = e.get_item(); 
        sender.set_text(item.get_attributes().getAttribute("days")); 
    } 
</script> 
 

Tags
ComboBox
Asked by
Carl
Top achievements
Rank 1
Answers by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or