Select distinct using LINQ and bound to a dropdown list with id and display name

Hi,
On one of my sharepoint page, I want to populate dropdown list with countries, namely
<asp:DropDownList ID="ddlCountry" runat ="server"></asp:DropDownList>
In the code, I use LINQ:
 var country = (from p in dc.ProvCountries
                               select p.country_code ).Distinct();
            ddlCountry.DataSource = country;
                ddlCountry.DataBind();
I want the country_code to be  the ID, while the country_name will be the display name in the dropdown, how can that be done?
Thanks in advance.

Hi,
The following code for your check.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplicationLib
public partial class _Default : Page
protected void Page_Load(object sender, EventArgs e)
List<ProvCountries> list = new List<ProvCountries>();
list.Add(new ProvCountries { country_code = "201", country_name = "A"});
list.Add(new ProvCountries { country_code = "201", country_name = "B" });
list.Add(new ProvCountries { country_code = "202", country_name = "C" });
list.Add(new ProvCountries { country_code = "202", country_name = "D" });
var country = (from p in list select new { p.country_code, p.country_name }).DistinctBy(p => p.country_code).ToList();
ddlCountry.DataSource = country;
ddlCountry.DataValueField = "country_code";
ddlCountry.DataTextField = "country_name";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, new ListItem("Please select", ""));
class ProvCountries
public string country_code { get; set; }
public string country_name { get; set; }
static class DataDistinct
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
if (seenKeys.Add(keySelector(element)))
yield return element;
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support

Similar Messages

  • I am using IFrame and displayed Html page

    Hi Friends
                        I am using IFrame and displayed Html page in flex4
                        In this page open to Firefox But not IE please help me.
                          Thanks
                           V.ChandraSekhar

    You have deleted your page, but you have not deleted your page?
    Which is it?
    If you never saved it it is gone. If you saved it in Lion (OSX 10.7) with Pages 09 v4.1, there should be versions available when you mouse overv the document name at the top of the window.
    Peter

  • Using an Array to Populate a DropDown List

    Using LCD 8
    Want to populate one dropdown list - with up to 24 items - based on a radio button selection.
    If RBG== 1, then display dropdown list with values pertaining to value "1".
    I have the dropdown list working.
    (rinse and repeat)
    However, I have coded each 'addItem' with a value.
    So, if I have 3 radio buttons - I code for 72 different 'addItems'.
    There is also a very good chance that some selections will only result in 3 values - where as other selections may yield 12 or 24.
    I want to use global variables as an array (I think) and then be able to loop through these variables and populate the dropdown list with each pass of the loop.
    This reduces the code from '72 lines' to 'very few lines').
    The variable values for each RBG value are set in a script object.
    How do I use/declare an array for my variables??

    Sorry about that. I had the link ready to paste but neglected to do so: http://acrobatusers.com/tutorials/getting-external-data-into-acrobat-x-javascript
    The idea is that you can read in data from an external or attached file, but it will need to be a different format such as XML, tab-delimited text, or CSV, which can all be exported from a spreadsheet.

  • How to add a service account in SQL Server to display the "Service Account Name" and "Display Name"

    Can someone
    help with steps on how to add the following in SQL Server 2012 environments?<o:p></o:p>
    "Service Account Name" and "Display Name"<o:p></o:p>
    Your help will be greatly appreciated.<o:p></o:p>
    leonie6214

    Hello,
    Is the following article what you are looking for?
    http://msdn.microsoft.com/en-us/library/ms345578.aspx
    If not, could you explain a little bit more what you want to accomplish?
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Default sales org on selection screen using set and get parameter!!

    Hi,
    I need to default value on selection screen using SET n GET parameter...logic to be used should be:
    Sales Organisation:
    This field should be filled by default using the user parameter id VKO. (using sentence GET PARAMETER and SET PARAMETER)...
    Hope i need to write the code in initialisation and what shud b the content?
    Regards
    Gunjan

    hi,
    TABLES <table name>.
      SET PARAMETER ID VKO FIELD <tablename-fieldname>.
    call transaction 'zxx'.
    try this sample program,
    REPORT BOOKINGS NO STANDARD PAGE HEADING.
    TABLES SBOOK.
    START-OF-SELECTION.
      WRITE: 'Select a booking',
      SKIP.
    GET SBOOK.
      WRITE: SBOOK-CARRID, SBOOK-CONNID,
             SBOOK-FLDATE, SBOOK-BOOKID.
      HIDE:  SBOOK-CARRID, SBOOK-CONNID,
             SBOOK-FLDATE, SBOOK-BOOKID.
    AT LINE-SELECTION.
      SET PARAMETER ID: 'CAR' FIELD SBOOK-CARRID,
                        'CON' FIELD SBOOK-CONNID,
                        'DAY' FIELD SBOOK-FLDATE,
                        'BOK' FIELD SBOOK-BOOKID.
      CALL TRANSACTION 'BOOK'.
    regards,
    siva
    Message was edited by:
            Shan

  • Select images using keywords and view slideshow...using what?

    I have a library full of jpeg images that were created either using the export command from LR or by editing in Br/Ps and then savedAs jpeg. Now I want to watch slideshows on my monitor (30" Apple HD Cinema Display). Now I have the following Dilemma:
    - I can start a Search Command in Bridge and narrow it down to exactly the images I want in my slide show. Then from the View menu select Slideshow. The IQ is terrible. True sharpness is only revealed when zooming in 100% but that's not the idea of a slide show.
    - I can also use Apple OS's (Tiger) built-in slide show and start it from the finder. That way I get high quality, fast dissolving slide shows, that are unfortunately limited to the first 100 images in the Finder view. However, in the Finder I cannot select my images using keywords and IPTC info.
    So could there be a simple solution to the problems I'm running into with Bridge?
    Or could there be a nice viewer for MacOS that features the search option I want and renders good images and dissolve option?
    Thanks.

    @Ann Shelbourne: Thanks for your reply. I'm hesitant to upgrade to CS4 at this point. That would mean my only option is to look for a jpeg viewer other than Adobe that can select images based on keywords and iptc data. Would you know one that does?
    @Ramon G Castaneda: I apologise for being an inexperienced forum visitor. I will take note of your advice and follow the posting instructions.
    I checked FAQ's both here and at Adobe, as well as the knowledge base. No results. I also searched the forum.
    My setup: MPB dual core Intel, 2GB RAM, 30GB free disk space. Adobe CS3, just updated to Bridge version 2.1.1.9. No improvement at all so far. According to Ann only CS4 will solve the problem.
    Thank you.

  • I need to pass multiple select options using submit and reutrn

    dear all,
    my requirement is i need to pass multiple values for work center like(biw01,biw02,biw03    etc) for this iam giving as biwl* and biot* for the tcode zpp_hmm ,using this i am going to get total working hours of perticular equiment.
    for this iam using submit and return query but iam unable to pass multiple work centers as input.
    my code is
    DATA : z_budat TYPE  RANGE OF budat,
           wa_budat LIKE LINE OF z_budat.
    wa_budat-low = '20111001'.
    wa_budat-sign = 'I'.
    wa_budat-option = 'BT'.
    wa_budat-high = '20111031'.
    APPEND wa_budat TO z_budat.
    CLEAR wa_budat.
    *wa_budat-High = '20111031'.
    *wa_budat-sign = 'I'.
    *wa_budat-option = 'BT'.
    *append wa_budat to z_budat.
    DATA : z_arbpl TYPE  RANGE OF arbpl,
           wa_arbpl LIKE LINE OF z_arbpl.
    wa_arbpl-low = 'BIWL*'.
    wa_arbpl-sign = 'I'.
    wa_arbpl-option = 'EQ'.
    APPEND wa_arbpl TO z_arbpl.
    CLEAR wa_arbpl.
    wa_arbpl-high = 'BIOT'.
    *wa_arbpl-sign = 'I'.
    *wa_arbpl-option = 'BT'.
    *APPEND wa_arbpl TO z_arbpl.
    SUBMIT   zpp_rep_hemm_perf WITH s_bukrs = '1004'  WITH s_budat IN z_budat WITH      s_werks = 'SMJT'
                   with   S_ARBPL IN Z_ARBPL USING SELECTION-SCREEN '1000' AND RETURN.
    but my doubt is whether it is corect or wrong what ever i am passing inputs for arbpl.
    thanks in advance.

    You can pass all parameter (rsparams-kind = 'P') and select-options (rsparams-kind = 'S') as a single internal table of type RSPARAMS. Go on appending the field names and values as rows and pass using SELECTION-TABLE parameter of SUBMIT command.
    I gave appending one set of selection values for s_budat field but you can go on appending more values for s_budat and other fields.
    DATA: lt_rsparams TYPE TABLE OF rsparams,
          ls_rsparams TYPE rsparams.
    CLEAR ls_rsparams.
    ls_rsparams-selname  = 'S_BUDAT'.
    ls_rsparams-kind = 'S'.
    ls_rsparams-sign = 'I'.
    ls_rsparams-option = 'BT'.
    ls_rsparams-low =  '20111001'.
    ls_rsparams-high = '20111031'.
    APPEND ls_rsparams TO lt_rsparams.
    SUBMIT zpp_rep_hemm_perf WITH SELECTION-TABLE lt_rsparams
                      USING SELECTION-SCREEN '1000'
                      AND RETURN.

  • SENDING AN EMAIL USING BCC AND RECIPIENT NAME APPEAR IN TO FIELD

    I'm sending and email to several people using the BCC field.  However, when the recipients receives the email, I want the recipient's name to appear in the TO field and the recipient not know the email was sent using the BCC.  Right now, the
    recipient knows it was sent BCC because their name is not appearing in the address fields

    Hi Vinay,
    You can use action defintions to send emails to your employee responsible.
    for that pls check action profile 'Order_Messages' and within this, action definition
    'ORDER_CONFIRMATION'.
    Check in there. Partner funtion is assigned to it, in second level customizing and smart form to be mailed in third level customizing.
    Prerequisite: emails should be maintained in BP master.
    For your requirement you can  do following settings:
    In second level customizing(i.e. selecting the action definition and double click on the same)
    Enter the partner funtion of Emp. responsible. in 'Partner Determination for the Action' Details. and check 'Partner Dependent'.
    Secondly, in details for 'Action Determination and Action Merging' in 'Action Merging' details select 'Max. 1 Unprocessed Action for Each Action Definition.
    Save the settings.
    Schedule the actions using action scheduling.
    Best Regards,
    Pratik Patel
    <b>Reward with Points!</b>

  • Dynamic Select Options/Ranges Maintain and Display in my screen

    Hi I am trying to figure out if I can create a screen which will will read various select-options I have stored in a custom table but am having trouble finding something which will allow me to display each of 'select-options' in my dynpro... has anyone ever done this?
    I'd rather not reinvent the wheel or mimic - does anyone know of a way to basically use a loaded range and display it on a screen for display or maintenance using standard SAP routines/classes?
    Thanks in advance!
    Roc..

    @Adrian - I got your email regarding the code sample, here is a quick example of how to popup a dynamic selection for up to 5 tables...
    *& Report  ZRS_DYNAMIC
    REPORT  zrs_dynamic.
    * START Dynamic Range Selection Definitions
    * Definition of the selection_if variable, which is used to reference
    * the selections obtained
    DATA: gv_selid TYPE rsdynsel-selid.
    * Definition of the TABLES_TAB table for use in providing the list of
    * fields available for creating select options from
    DATA: gt_tables TYPE STANDARD TABLE OF rsdstabs.
    DATA: gs_tables TYPE rsdstabs.
    PARAMETERS: p_tab1 TYPE tabname DEFAULT 'KNA1',
                p_tab2 TYPE tabname DEFAULT 'KNB1',
                p_tab3 TYPE tabname DEFAULT 'KNC1',
                p_tab4 TYPE tabname DEFAULT 'KNVV',
                p_tab5 TYPE tabname DEFAULT 'KNVP'.
    START-OF-SELECTION.
      gs_tables-prim_tab = p_tab1 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab2 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab3 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab4 .APPEND gs_tables TO gt_tables.
      gs_tables-prim_tab = p_tab5 .APPEND gs_tables TO gt_tables.
    * Definition of Table which includes the select-option range for field
      TYPES: ty_selopt_t TYPE  rsdsselopt OCCURS 10.
    * Definition of field name and select option range table
      TYPES: BEGIN OF ty_frange,
               fieldname TYPE rsdstabs-prim_fname,
               selopt_t TYPE ty_selopt_t,
             END OF ty_frange.
      TYPES: ty_frange_t TYPE ty_frange OCCURS 10.
      TYPES: BEGIN OF ty_range,
               tablename LIKE rsdstabs-prim_tab,
               frange_t TYPE ty_frange_t,
             END OF ty_range.
      TYPES: ty_range_t TYPE STANDARD TABLE OF ty_range.
      DATA: it_ranges TYPE ty_range_t.
    * work areas
      DATA: gs_ranges TYPE ty_range.
      DATA: gs_frange TYPE ty_frange.
      DATA: gs_selopt TYPE rsdsselopt.
      DATA: gt_ranges TYPE ty_range_t.
      DATA: gt_frange TYPE ty_frange_t.
      DATA: gt_selopt TYPE ty_selopt_t.
    * Definition of the fields list avaiable
      TYPES: ty_fields TYPE STANDARD TABLE OF rsdsfields.
      DATA: it_fields TYPE ty_fields.
      DATA: gs_fields TYPE rsdsfields.
    * END Dynamic Range Selection --------------------------------------------
      CALL FUNCTION 'FREE_SELECTIONS_INIT'
        EXPORTING
          kind         = 'T'
        IMPORTING
          selection_id = gv_selid
        TABLES
          tables_tab   = gt_tables.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
        EXPORTING
          selection_id    = gv_selid
          title           = 'Select WHERE criteria for Rule'(s12)
          as_window       = 'X'
          start_row       = 7
          start_col       = 10
        IMPORTING
          field_ranges    = it_ranges
        TABLES
          fields_tab      = it_fields
        EXCEPTIONS
          internal_error  = 1
          no_action       = 2
          selid_not_found = 3
          illegal_status  = 4
          OTHERS          = 5.
    Edited by: Rocco Scocco on Jun 17, 2010 3:48 PM
    Edited by: Rocco Scocco on Jun 17, 2010 3:49 PM

  • Select most recent file and display

    I've been considerig this and I am closer to how I expect it to work
    This is what I have so far but can't peice together just yet.
    Get the current open folder window look for the last item if shot within the last 30 secs of the creation date, if shot within 30 secs then select/highlight the file and use system events to press keystroke y using cmd and option down.(to put it on the screen in full screen) Display for 15 secs, or if esc hit then wait for next file to arrive and so on.
    If the window is closed of the current open folder then end applescript.
    This is how far I have got but can't link the ideas together well.
    set theWindow to name of front window of application "Finder"
    set theWindow to name of front window of application "Finder"
    set theFldr to path of theWindow
    tell application "Finder"
              set theContents to sort items of theFldr by creation date
              set theLastimage to (contents of item 1 of theContents) as text
      --is it within the last 30 seconds?
      -- yes, then
              tell application "System Events"
      keystroke "y" using {command down, option down}
                        delay 15
      key code 53
      --then wait for arrival of next image. and repeat.
      --if theWindow is close end applescript.
              end tell
    end tell

    Hi,
    If you don't want to use a folder action, try this :
    try
          tell application "Finder" to set currFolder to name of front Finder window
    on error
          return -- no Finder window
    end try
    set tDate to (current date) - 30
    repeat
          set b to false
          tell application "Finder"
                set fWindows to Finder windows whose it's name is currFolder
                if (fWindows is not {}) then
                      set tWind to item 1 of fWindows
                      set nFiles to document files of tWind whose creation date > tDate -- get newer files
                      set tDate to (current date)
                      if nFiles is not {} then
                            reveal nFiles
                            my selectionfullScreen(currFolder, count nFiles)
                            set b to true
                      end if
                else
                      exit repeat -- quit the script, the current Folder is closed
                end if
          end tell
          if not b then delay 5 -- no recent files, wait 5 seconds
    end repeat
    on selectionfullScreen(tName, n)
          tell application "System Events"
                tell process "Finder"
                      set frontmost to true
                      keystroke "y" using {command down, option down}
                      repeat (15 * n) times
                            tell window 1 to if (exists) and (its title is tName) then return -- the user close QuickLook
                            delay 1
                      end repeat
                      tell window 1 to if (exists) and (its title is not tName) then key code 53 -- close QuickLook after (15 seconds X (number of images))
                end tell
          end tell
    end selectionfullScreen

  • Selecting first 15 rows and displaying next 15

    I wish to select the first 15 rows from my database and then have an option select a next page, whereby the next 15 rows are displayed. I'm not sure how to go about it, could someone enlighten me. For reference, it would be something like how the forums is done, whereby they display x amount of threads, and you would have to go to the next page.

    This can be done by retrieving the first 15 using something like rownum <= 15 in the where clause.
    Then, by remembering the ID of the last thread that was displayed you select threads id > lastID and rownum <= 15... that is the first 15 rows that match your query starting immediately after the last thread searched.
    It's not unusual to retrieve and store a list of the Thread IDs completely as this allows a more stable feedback at the expense of heavier session information being stored.
    Hope that helps
    Talden

  • Generating Parent Number using Level and Display Number

    I am facing problem in generating parent number using level and dispaly number.
    Here is the table structure
    CREATE TABLE test(
    DISPLAY_NUMBER       NUMBER,
    LEVEL_NUM           NUMBER,
    COMPONENT   VARCHAR2(10))
    INSERT INTO test VALUES (1,1,'A');
    INSERT INTO test VALUES (2,2,'B');
    INSERT INTO test VALUES (3,3,'C');
    INSERT INTO test VALUES (4,4,'D');
    INSERT INTO test VALUES (5,3,'E');
    INSERT INTO test VALUES (6,3,'F');
    INSERT INTO test VALUES (7,2,'G');
    INSERT INTO test VALUES (8,3,'H');Here is the output table structure and required output data format
    CREATE TABLE test1(
    DISPLAY_NUMBER       NUMBER,
    LEVEL_NUM           NUMBER,
    COMPONENT   VARCHAR2(10),
    PARENT VARCHAR2(10))
    INSERT INTO test1 VALUES (1,1,'A',NULL);
    INSERT INTO test1 VALUES (2,2,'B','A');
    INSERT INTO test1 VALUES (3,3,'C','B');
    INSERT INTO test1 VALUES (4,4,'D','C');
    INSERT INTO test1 VALUES (5,3,'E','B');
    INSERT INTO test1 VALUES (6,3,'F','B');
    INSERT INTO test1 VALUES (7,2,'G','A');
    INSERT INTO test1 VALUES (8,3,'H','B');Oracle database version : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    Thanks in advance.
    Regards,
    Laxman

    >
    I am facing problem in generating parent number using level and dispaly number.
    >
    Thanks for posting the table DDL and data. I called the tables testa and testb.
    insert into testb
    select a.*, (select component from testa b where b.level_num + 1
      = a.level_num and rownum = 1) parent
    from testa a
    select * from testb
    DISPLAY_NUMBER,LEVEL_NUM,COMPONENT,PARENT
    1,1,A,
    2,2,B,A
    3,3,C,B
    4,4,D,C
    5,3,E,B
    6,3,F,B
    7,2,G,A
    8,3,H,B

  • Select Date between range and display

    Hello - i need some ideas to the following:
    I need to create a form to submit some information, with the
    date that form was submitted, to a database using php.
    Once the form is submitted i need to retrieve multiple rows
    from the database based on a selected date range, and display the
    information
    Question one - any ideas on the flow that i need
    question two - how do you think that i best record the date -
    given that i need to select a range later.
    question three - how do I select mutiple rows give a range of
    dates
    Thanks

    Hello - i need some ideas to the following:
    I need to create a form to submit some information, with the
    date that form was submitted, to a database using php.
    Once the form is submitted i need to retrieve multiple rows
    from the database based on a selected date range, and display the
    information
    Question one - any ideas on the flow that i need
    question two - how do you think that i best record the date -
    given that i need to select a range later.
    question three - how do I select mutiple rows give a range of
    dates
    Thanks

  • Creating Bar Charts using Java and Display in jsp

    Hi..Is it possible to create a servlet that processes data from database and display the values as Bar Charts in jsp pages. If its possible, is there any examples on how to achieve that?

    I don't get it. You already know what needs to be done to solve your problem, the only thing you are missing is the HOW. That's the easy part, if only you break down what you have to know:
    1) how do I show an image on a website (this is a basic HTML question actually, not actually related to servlets/JSPs directly)
    2) how do I fetch the path from a database (JDBC question) so that I can use this path to link to my image on disc
    So what is preventing you from figuring out how to do these two simple tasks? Some clever google searches should give you all the information you need in no time.
    by the way: are you sure that you need to store these paths in the database? Is this part of some file upload component?

  • How do I upload an image using as3 and display it without a server?

    Is it possible to upload an image using as3 and flash player 9 and then display it in a movie clip without server side assistance?
    thanks,
    JB

    Hi,
    Check out the links..
    I hope it will helps u.
    http://labs.findsubstance.com/2008/04/03/as3-upload-encode-images/
    http://flexscript.wordpress.com/2009/01/12/uploading-an-image-into-flash-without-server-si de-script-using-flash-player-10/
    Saransoft

Maybe you are looking for