Combining data to use in DataTextField

5 posts, 1 answers
  1. Joe
    Joe avatar
    23 posts
    Member since:
    Nov 2010

    Posted 13 Sep 2011 Link to this post

    Good Evening,

    I need to create a dropdown that contains to fields from a database seperated by a hyphen "-".

    How would I do that using the following code:

    public void radcombo_mns_incidents_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        radcombo_mns_incidents.DataTextField = "INCIDENT_ID";
        radcombo_mns_incidents.DataValueField = "INCIDENT_ID";
        radcombo_mns_incidents.DataSource = from c in quarkdb.MNs
                                            join t in quarkdb.STATUS_TYPEs on c.STATUS equals t.RECORD_ID
                                            where t.STATUS != "Closed"
                                            select new
                                            {
                                                c.INCIDENT_ID,
                                                c.TITLE
     
                                            };
        radcombo_mns_incidents.DataBind();

    I would like the text field to display INCIDENT_ID - TITLE, so that they dropdown would have:

    34556222 - Outage in location blablah
    34544566 - Outage in location hahaha
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Sep 2011 Link to this post

    Hello Joe,

    I tried the following markup and it worked as expected.
    aspx:
    <telerik:RadComboBox ID="RadComboBox1" runat="server">
      <ItemTemplate>
       <%# DataBinder.Eval(Container.DataItem, "FirstName") %>-
       <%# DataBinder.Eval(Container.DataItem, "LastName") %>
      </ItemTemplate>
    </telerik:RadComboBox>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe
    Joe avatar
    23 posts
    Member since:
    Nov 2010

    Posted 13 Sep 2011 Link to this post

    Thanks, that worked!

  5. Joe
    Joe avatar
    23 posts
    Member since:
    Nov 2010

    Posted 13 Sep 2011 Link to this post

    Hmmm, I just noticed that when I select an item from the dropdown, I see the fields wrapped in "{ }". The dropdown itself looks correct, but once you select an entry, this shows up in the box:

    { INCIDENT_ID = 9142011-709, TITLE = Test }
  6. Joe
    Joe avatar
    5 posts
    Member since:
    Oct 2010

    Posted 13 Sep 2011 Link to this post

    Found my issue, I had assumed that :
    radcombo_mns_incidents.DataTextField = "INCIDENT_ID";

    would interfere with your recommendation Princy, so I commented it out. Once I removed the comments, the INCIDENT_ID is displayed when its selected.

    Thanks.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017