Trees and Unmanaged Dropdown Lists

Does anybody know if it's possible to create heirarchical property value lists? For example, we want to have a keyword system for documents and users with some top-level categories and then some more specific categories under them, and not just one long unorganized list. Is this possible to do using trees and/or unmanaged dropdown lists? I'm not sure how to make these. Do you have to insert a table into SQL server somewhere?

Yes, you can do this.  I don't have the benefit of access to my database from where I am at the moment, so please pardon me if I get some of this wrong.
* There's a sample table in your primary portal database called something like "samplepicklist" - that will show you the data structure
* You create a tree property
* Bind that property to the table...
In my case I'm using it to provide a region/country hierarchy list for user info.
1) Property is named "Country (by Region)"
2) Set values to...
        - Property is visible in the UI (checked)
        - Searchable (checked)
        - Type is "Tree" (when you select this the screen will change)
3) got a view together - view is called "vw_PTProfile_RegionCountries".  Set the Database Table Name setting to the name of your view or table.
4) Provide your hierarchy info.  There are two bits - display/storage value name and ordering key.  In my case my values look like...
    PICK COLUMN                        SORT ORDER
    rgn_descr                              rgn_id
    country_descr                        country_id
Blammo - done.  I now have a hierarchical region/country list.
NOTES:
* I'd suggest using a view so you can link to other data sources, etc. and not worry as much about shaping the data the way the portal needs it
* The property works on most classes of objects EXCEPT documents.  This isn't an issue with the property as much as the document property editing approach ("documents are special objects")
That help?
I love these kinds of things and want to make best use of them myself, so if anyone has any ideas on how to kick the portal into overdrive using properties (or sees that I'm mis-using this approach or steered Dave in the wrong direction) please, please do respond to this thread.
Thanks,
Eric

Similar Messages

  • Convert Word 2007 Form to PDF Form not creating dropdown list fields

    I created a new word document with all my text fields with lines and 5 dropdown list fields with all their values.  Works great in Word 2007.  When I convert it to a pdf form (Acrobat Pro X) none of the dropdown list fields get created.  The text fields do, but no drop downs.  If I have to create them all manually in Acrobat, what's the point of doing all the work in Word?

    The Word conversion to PDF and Forms Wizard do not detect and do not know how to complete a drop down box. I do not even create the form fields in Word as there is no transfer to the PDF. I also find the Wizard lacking in proper naming and grouping. It is just easier and more efficient to add the fields manually or with JavaScript tools.
    The only product that can do this is apache OpenOffice when an author creates the from body and form fields in the Writer application and then exports to a PDF.

  • Difference between Combo Box and Dropdown List

    Hi All,
    I would like to know the difference between the elements 'Combo box' and 'Dropdown List' in VC. I am facing an issue where i am invoking an entry list and the output of the first element the entry list returns is getting reflected as the output for all the elements...
    So even if 2nd and 3rd row of the o/p from the entry list is giving only 2 items, if the 1st row returns only 1 then we are able to see only 1 item. Its as if the 1st row decides the items to be returned for all the rows.
    Please help.

    Hi Hezi,
    I have 2 columns in my table. First column is 'material number' and the 2nd one is 'production version'. There can 1,2 or 3 production version for each material. [This information is stored in the backend] This is retrieved through a method which invokes a bapi which in turn retrieves from the backend.
    I have provided a dropdown list for the 'production version' column. Lets say there are 2 rows. Material 1 and material 2. Lets say material 1 has 1 production version and material 2 has 2 production version. So rightfully speaking i should have 1 option in the dropdown for material 1 and 2 for material 2.
    But what i seeing is only 1 option for both the materials. This is wrong.
    Is there something that can be done to ensure that each row reflects the correct no. of options in the dropdown?

  • Unable to embed External CSS file, dropdown list,filter panel and dimension filter are not working in SAP Design Studio Tool

    Hello Everyone,
    I am new to SAP Design Studio. I am working on creating dashboards and I am using Design Studio 1.2 version. Please suggest some solutions for the following issues. Thanks in Advance.
    1. External CSS file which is embeded using custom CSS option under "application component properties" is not working.
        * I kept the external CSS file inside repository-> my application folder.
    2. During runtime, getting javascript error while selecting '-' option from filter panel.
    3. Unable to select or type dimension name under "dimension filer component" properties.
    4. Getting runtime error for dropdown list, and I have inserted the following code under "onStartup" option of Application component properties.
    "DROPDOWN_1.setItems(DS_1.getMemberList("PRODUCTREF", MemberPresentation.INTERNAL_KEY, MemberDisplay.TEXT, 20));
    and dimension values are not populated in auto suggest."

    There should be an Error Log under View > Error Log that gives you more details of these errors.  Could you add that?  There is also a View > Script Problems log that provides more details as well.

  • Report with ALV tree and ALV list?

    I need to create a report with layout as same as this one
    [http://trangiegie.com/MyFile/output.JPG]
    It looks like a report with combination of ALV tree and list. The tree works like a navigation bar. Wonder if there are any demo programs like this. Will appreciate any help.

    For Tree alone - You can check program : BCALV_TREE_02
    Program Name                   Report title
    BCALV_GRID_DND_TREE            ALV Grid: Drag and Drop with ALV Tree
    BCALV_GRID_DND_TREE_SIMPLE     ALV GRID: Drag and drop with ALV tree (simple)
    BCALV_TEST_COLUMN_TREE         Program BCALV_TEST_COLUMN_TREE
    BCALV_TEST_SIMPLE_TREE         Program BCALV_TEST_SIMPLE_TREE
    BCALV_TREE_01                  ALV Tree Control: Build Up the Hierarchy Tree
    BCALV_TREE_02                  ALV Tree Control: Event Handling
    BCALV_TREE_03                  ALV Tree Control: Use an Own Context Menu
    BCALV_TREE_04                  ALV Tree Control: Add a Button to the Toolbar
    BCALV_TREE_05                  ALV Tree Control: Add a Menu to the Toolbar
    BCALV_TREE_06                  ALV tree control: Icon column and icon for nodes/items
    BCALV_TREE_DEMO                Demo for ALV tree control
    BCALV_TREE_DND                 ALV tree control: Drag & Drop within a hierarchy tree
    BCALV_TREE_DND_MULTIPLE        ALV tree control: Drag & Drop within a hierarchy tree
    BCALV_TREE_EVENT_RECEIVER      Include BCALV_TREE_EVENT_RECEIVER
    BCALV_TREE_EVENT_RECEIVER01
    BCALV_TREE_ITEMLAYOUT          ALV Tree: Change Item Layouts at Runtime
    BCALV_TREE_MOVE_NODE_TEST      Demo for ALV tree control
    BCALV_TREE_SIMPLE_DEMO         Program BCALV_TREE_SIMPLE_DEMO
    BCALV_TREE_VERIFY              Verifier for ALV Tree and Simple ALV Tree

  • How can I use a Dropdown list in a table col and only get the choosen key?

    hi!
    I have chosen Cell editor = Dropdown for two of the columns in my WD table  (ordinary Table not ALV) .
    When the table is displayed the first time this looks OK, but if a user selects a value from the dropdown list, both the key and the explanation text is copied into the cell, and the cell column is automatically widened. I want to copy the key value only, and not the connected text. How is this possible?
    I started setting the table as fixed and setting the width on the column, but this was a puzzle I gave up since there are quite a lot of columns.
    regards, Tine

    Well , the problem is that in the dropdown list I want to see both the key value and the text, like you do in SAP GUI. Fex. if I would like to create a dropdown for langauges, factory calendar or countries, I want to see both the country code (the key) and the name of the country in the dropdown list, and then when user choose a line I would only like to see the keyvalue in the input field.  Right now I concatenate the key and the text into the 'value' in the valueset table.
    In some cases the user knows the key value better than the explanational text, and then it is good to show both values. But sInce I would like to save space in the table displayed in the view I only want to show the key values selected in the table (ex. NO if user choose Norway) .
    But maybe it is better to create this kind of input help as an OVS with no input fields .?

  • Display month and year in dropdown list on selection screen

    Hi
      Can anyone tell me how to display months and year in a dropdown list on a selection screen?
      also please tell me how to get the first and the last dates upon selecting the month and year on the dropdown list.
    Month: January Year:2007 . 
    After selecting the required month and year, the first date and last date i.e '01.01.2007 - 31.01.2007' should be displayed on the right side.
    Reward Points assured..
    thanks,
    Chetan

    Hi..,
    <b>
    Just copy, paste and execute this program !!</b>
    type-pools: vrm.
    parameters : p_month(2) type n as listbox visible length 10,
    p_year(4) type n as listbox visible length 10.
    DATA : W_DATE type d, w_ldate type d.
    initialization.
    perform user_drop_down_list_fordt.
    perform user_drop_down_list_foryr.
    start-of-selection.
    concatenate p_year p_month '01' into w_date.
    call function 'BKK_GET_MONTH_LASTDAY'
      exporting
        i_date        = w_date
    IMPORTING
       E_DATE        = w_ldate
    write /: w_date,w_ldate.
    build user_drop_down_list
    form user_drop_down_list_fordt.
    data: name type vrm_id,
    list type vrm_values,
    value like line of list.
    data: t_months type t247 occurs 0 with header line.
    clear list. refresh list.
    name = 'P_MONTH'.
    select * into  table t_months
    from t247 where spras eq 'EN'.
    sort t_months ascending by mnr.
    loop at t_months.
    clear value.
    value-key = t_months-mnr.
    value-text = t_months-ltx.
    append value to list.
    endloop.
    Set the values
    call function 'VRM_SET_VALUES'
    exporting
    id = name
    values = list.
    endform.
    for year...
    form user_drop_down_list_foryr.
    data: name type vrm_id,
    list type vrm_values,
    value like line of list.
    clear list. refresh list.
    name = 'P_YEAR'.
    do 9999 times.
    clear value.
    value-key = sy-index.
    append value to list.
    enddo.
    Set the values
    call function 'VRM_SET_VALUES'
    exporting
    id = name
    values = list.
    endform.
    <b>
    Hope this solves ur problem..</b>
    regards,
    sai ramesh

  • Ipod not in dropdown list and itunes won't play from ipod after 8.1download

    ever since I downloaded 8.1 itunes my ipod no longer appears in the dropdown list (right click on song or podcast - add to playlst) when i want to transfer a song or podcast to my ipod. My only option is to drag and drop now. Also I cannot play on my computer a song or podcast that is on my ipod,(I do this to sync my ipod to where it last played) it's as though it is not recognizing it even though my ipod icon does appear in itunes. I use a 1GB shuffle.

    i knew the solution was in front of my face! thank you so much pointing it out for me : )

  • How to create a textbox and dropdown list in Java similar to google search

    Hi,
    I want to create a textbox and dropdown in java very much similar to google search . As user types in the letters it should display the dropdown list similar to google. Can anyone help me with this one asap.
    Thanks
    Lavanya

    But my real problem is how to apply the chmod 777 on a folder containing spacesSo why not say so in the first place?
    Runtime.exec ("chmod 777 My\\ Folder");Runtime.exec(new String[]{"chmod", "777", "My Folder"});
    That is why I chose the example of mkdirYour reasoning on this point is incomprehensible. You wanted help with A so you asked about B. Just wasting time.

  • How to populate a textfield based on a dropdown list and a checkbox

    Hi Guys,
    I need help.
    first step: I have a dropdown list if i click in dropdownlist "a" and put in numeric field a number bigger than 99 the, checkbox should be marked and  second step: a textfield1 should be visible.
    the first step works perfectly but the second doesnt work.
    this is my coding for the second step in event : change java script
    if ((DropDownList1.rawValue == "a") && (this.rawValue == 1))
    TextField1.presence = "visible";
    else
    TextField1.presence = "hidden";
    does anybody have any idea why?
    thanks!!
    Diana

    Hi,
    I would put the following in the exit of the dropdown and the checkbox:
    if 
    (DropDownList1.rawValue == "a" && CheckBox1.rawValue == 1){
    TextField1.presence
    = "visible";}
    else
    TextField1.presence
    = "hidden";}
    (the script is all over the shop, but should be OK in the form).
    Then in the exit event of the numeric field (after the changing of the checkbox value) you could call the checkbox exit event.
    Good luck,
    Niall

  • Link db results to Dropdown list and link to email

    I need to pull information from a table 'Suppliers' in an (datebase.mdb) and retrieve two items, name and email. This in itself Dreamweaver makes fairly simple. From this information I need to produce a dropdown list, again Dreamweaver makes this simple.By the way we are using the Suppliers table as 'Departments'.
    Now the real work begins and this question. Once the user selects a name on this dropdown list, I need to create a feed of the email address associated with the selected name and pass it to an email form field as a BCC. This form (email) is generated by another subroutine, so I will also have to add the necessary coding for the form to include this BCC email address if selected.
    I wish to add the new dropdown list just below the subject and as this is an optional field, the first selection should be 'optional' and do nothing if no selection is made by the user.
    I believe that the form is generated by the 'shopcustcontact' and results passed to 'shopmailform' for final processing and sending.
    I appreaciate your input this this question.

    This isn't a Design question. Please repost in the Dreamweaver forum.

  • Both attribute value and description showing on attribute value dropdown list

    Hi All,
    I am using CRM 7.0 EhP 1 and I have encountered a item I need to address in regard to the display of a Marketing Attribute values on the Account Overview page (BP_HEAD/BPHEADOverview) on the Web Client.
    The component in question on the page is BP_DATA/MarketingAttributesEOVP.
    The value dropdown lists for each attribute show both the Attribute Value (in my case a number) and Description. We require that only the Description is shown and not the Attribute Value in brackets also.
    Is there a user setting that controls this or is displaying both standard with no adjustment possible through user settings or configuration? 
    Thanks,
    Jonathan

    Hi All, 
    The following OSS note looks to resolve issue in question above:
    1647509 - Attributes value shown as value+description in accounts page
    Thanks for your assistance.
    Jonathan

  • After clearing cache and cookies, my same dropdown list keeps returning when I log in to Facebook.

    After clearing cache and deleting cookies, my same dropdown list keeps on returning whenever I log in to Facebook. I need to know how to delete login history.

    That data is called Form History
    Options/Preferences > Privacy > Clear your recent history > Everything + Form history

  • Issue : drag and drop from list control to tree control

    Hi,
    I was trying a drag and drop from list control to tree control. I have used some sample data to populate list and tree controls .
    It is working fine . except one problem ..
    Prob : when i drag an item to tree control .. it gets added .. now tree contains (X+1) data in list .. say X is the inital number of nodes in a tree node.
              now if i drag another item from list to last item in the tree node  .. i.e at X+1 index. .. it throws null pointer exception.
    I am considerably new in flex programming . looking for help from experts ..
    Below is my code :
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                    layout="horizontal"
                    creationComplete="init()">
        <mx:Script>
            <![CDATA[
                import mx.controls.listClasses.IListItemRenderer;
                import mx.rpc.events.FaultEvent;
                import mx.rpc.events.ResultEvent;
                import mx.utils.ObjectUtil;
                import mx.collections.ICollectionView;
                import mx.core.UIComponent;
                import mx.managers.DragManager;
                import mx.events.DragEvent;
                import mx.controls.Alert;
                import mx.controls.Label;
                import mx.events.CloseEvent;
                private var homePath:String="/home/e311394/dndTest/";
                private var destPath:String="/home/e311394/dndDest/";
                private var eid:String="e311394";
                private var actn:String;
                [Bindable]
                private var cm:ContextMenu;
                private var cmi:ContextMenuItem;
                [Bindable]
                private var dp:ArrayCollection;
                private function init():void
                    cmi=new ContextMenuItem("Remove");
                    cmi.enabled=true;
                    cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect);
                    cm=new ContextMenu();
                    cm.hideBuiltInItems();
                    cm.customItems=[cmi];
                    cm.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenuItem_menuSelect);
                    list.contextMenu=cm;
                private function contextMenuItem_menuSelect(evt:ContextMenuEvent):void
                    list.selectedIndex=lastRollOverIndex;
                private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void
                    var loclSelectedRow:Object=list.selectedItem;
                    var lostrSelectedMenuItem:String;
                    lostrSelectedMenuItem=evt.target.caption;
                    if (loclSelectedRow != null)
                        var obj:Object=new Object()
                        obj.label=loclSelectedRow.label as String;
                            //Alert.show(obj.label);
                    if (lostrSelectedMenuItem == "Remove")
                        if(loclSelectedRow!=null)
                        var pth:String=homePath.concat(loclSelectedRow.label);
                        //Alert.show(pth);
                        //FlexDnDRemoteService.process(eid,"delete",pth,"-"); 
                        var coll:ArrayCollection=list.dataProvider as ArrayCollection;
                        if (coll.contains(loclSelectedRow))
                            coll.removeItemAt(coll.getItemIndex(loclSelectedRow));
                public function onTreeDragEnter(event:DragEvent):void
                    event.preventDefault();
                    DragManager.acceptDragDrop(event.target as UIComponent);
                    tree.showDropFeedback(event);
                protected function onTreeDragOver(event:DragEvent):void
                    event.preventDefault();
                    event.currentTarget.hideDropFeedback(event);
                    try
                        var index:int=tree.calculateDropIndex(event);
                    catch (e:Error)
                        DragManager.showFeedback(DragManager.NONE);
                        return;
                    tree.selectedIndex=index;
                    var draggedOverItem:Object=tree.selectedItem;
                public function onTreeDragExit(event:DragEvent):void
                    event.preventDefault();
                    tree.hideDropFeedback(event);
                private function showAlert():void
                    Alert.yesLabel="Move";
                    Alert.noLabel="Copy";
                    Alert.buttonWidth=70;
                    Alert.show("Copy / Move ?", "Confirm", Alert.YES | Alert.NO | Alert.CANCEL, this, alertListener, null, Alert.OK);
                private function alertListener(eventObj:CloseEvent):void
                    var result:Boolean=false;
                    if (eventObj.detail == Alert.CANCEL)
                        //Alert.show("CANCEL");
                        return;
                    if (eventObj.detail == Alert.YES)
                        //Alert.show("YES");
                        result=true;
                    else if (eventObj.detail == Alert.NO)
                        //Alert.show("NO");
                        result=false;
                    var index:int=tree.calculateDropIndex(treedropevt);
                    //Alert.show("Drop Pos" + index.toString());
                    /* var treeList:ArrayCollection=tree.dataProvider as ArrayCollection;
                       Alert.show(" index"+index+"Length "+treeList.length);
                       if(index > treeList.length)
                       Alert.show("Returning");
                       return;
                    var items:Array=new Array();
                    if (treedropevt.dragSource.hasFormat("items"))
                        items=items.concat(treedropevt.dragSource.dataForFormat("items") as Array);
                    var parentItem:Object;
                    parentItem=getObjectTarget();
                    /* if (tree.dataDescriptor.isBranch(tree.indexToItemRenderer(index).data))
                       parentItem=tree.indexToItemRenderer(index).data;
                       else
                       var dropParentPackage:Object = tree.mx_internal::_dropData.parent as Object;
                       Alert.show("HAck"+dropParentPackage.toString());
                       parentItem=tree.getParentItem(tree.indexToItemRenderer(index).data);
                       //Alert.show("Lenght "+ObjectUtil.getClassInfo(parentItem).properties.length);
                    //Alert.show("Lenght "+ObjectUtil.getClassInfo(parentItem).properties.length);
                    var position:int=0;
                    /* if(ObjectUtil.getClassInfo(parentItem).properties.length==0)
                       Alert.show("Returning");
                       return;
                    if (parentItem != null)
                        try
                            while (tree.indexToItemRenderer(index).data != parentItem)
                                //Alert.show(tree.indexToItemRenderer(index).data.toString());
                                if (index > 0)
                                    index--;
                                //Alert.show("Insiade");
                                position++;
                        catch (e:Error)
                            Alert.show("Catch" + index.toString());
                            return;
                    for each (var item:Object in items)
                        var obj:Object=new Object()
                        obj.label=item.label as String;
                        if (parentItem != null)
                            //Alert.show("ADDED");                       
                            tree.dataDescriptor.addChildAt(parentItem, obj, position++);                       
                        else
                            //Alert.show("PARENT NULL");
                            tree.dataDescriptor.addChildAt(tree.selectedItem, obj, position++);                       
                        var spth:String=homePath.concat(item.label);
                        //Alert.show(spth);   
                        var dpth:String=destPath.concat(item.label);
                        //Alert.show(dpth);
                        if (result == true)
                            removeItems();
                                //FlexDnDRemoteService.process(eid,"move",spth,dpth);
                        else
                            //FlexDnDRemoteService.process(eid,"copy",spth,dpth);
                        tree.validateNow();
                public function getObjectTarget():Object
                    var dropData:Object=tree.mx_internal::_dropData as Object;
                    if (dropData.parent != null)
                        return dropData.parent;
                    else
                        // if there is not parent (root of the tree), I take the root directly
                        var renderer:IListItemRenderer=tree.indexToItemRenderer(0);
                        return renderer.data;
                public function removeItems():void
                    //remove moved elements
                    var items:Array=treedropevt.dragSource.dataForFormat("items") as Array;
                    var coll:ArrayCollection=list.dataProvider as ArrayCollection;
                    for each (var item:Object in items)
                        if (coll.contains(item))
                            coll.removeItemAt(coll.getItemIndex(item));
                private var treedropevt:DragEvent;
                public function onTreeDragDrop(event:DragEvent):void
                    treedropevt=event;
                    showAlert();
                    event.preventDefault();
                    tree.hideDropFeedback(event);
                public function resultHandler(event:ResultEvent):void
                    Alert.show("Success", "Status");
                public function faultHandler(event:FaultEvent):void
                    Alert.show(event.fault.faultString, "Failure");
            ]]>
        </mx:Script>
        <mx:ArrayCollection id="listDP">
            <mx:Object label="File1.dnd"/>
            <mx:Object label="File2.dnd"/>
            <mx:Object label="File3.dnd"/>
            <mx:Object label="File4.dnd"/>
            <mx:Object label="File5.dnd"/>
        </mx:ArrayCollection>
        <mx:Number id="lastRollOverIndex"/>
        <!--
             <mx:ArrayCollection id="treeDP">
             <mx:Object label="/home">
             <mx:children>
             <mx:Object label="dummy1.ks"/>
             <mx:Object label="dummy2.ks"/>
             <mx:Object label="e493126">
             <mx:children>
             <mx:ArrayCollection>
             <mx:Object label="/home/e493126/sample1.ks"/>
             </mx:ArrayCollection>
             </mx:children>
             </mx:Object>
             </mx:children>
             </mx:Object>
             </mx:ArrayCollection>
        -->
        <mx:ArrayCollection id="treeDP">
            <mx:Object label="/dndDest">
                <mx:children>
                    <mx:ArrayCollection>
                        <mx:Object label="sample1.ks"/>
                        <mx:Object label="sample2.ks"/>
                        <mx:Object label="sample3.ks"/>
                        <mx:Object label="sample4.ks"/>
                        <mx:Object label="sample5.ks"/>
                        <mx:Object label="sample6.ks"/>
                    </mx:ArrayCollection>
                </mx:children>
            </mx:Object>
        </mx:ArrayCollection>
        <mx:List id="list"
                 itemRollOver="lastRollOverIndex = event.rowIndex"
                 width="50%"
                 dragEnabled="true"
                 dataProvider="{listDP}"
                 labelField="label"
                 allowMultipleSelection="true"
                 dragMoveEnabled="false">
        </mx:List>
        <mx:Tree id="tree"
                 width="50%"            
                 dragEnabled="true"            
                 dataProvider="{treeDP}"            
                 dragEnter="onTreeDragEnter(event)"
                 dragOver="onTreeDragOver(event)"
                 dragExit="onTreeDragExit(event)"
                 dragDrop="onTreeDragDrop(event)"
                 labelField="label"
                 liveScrolling="true">
        </mx:Tree>
        <mx:RemoteObject id="FlexDnDRemoteService"
                         showBusyCursor="true"
                         destination="FlexDnD">
            <mx:method name="process"
                       result="resultHandler(event)"
                       fault="faultHandler(event)"/>
        </mx:RemoteObject>
    </mx:Application>
    Thanks,
    Rajiv

    Ya , i have searched and have used the same code.
    But needed to customize few things like:
    stop dnd in same tree
    drop some item into a folder ..( onto it ) etc
    have achieved the same .. but this issue ..
    i think the tree dataprovider (contents internally is not being updated .. only the UI)
    any suggestions ?
    - Rajiv

  • 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

Maybe you are looking for

  • How to pop-up window in swf inside a html?

    there is pop-up blocker in browsers. how can i pop-up window as well? what scripts should i type in fla file and html file? pls help!~

  • Start up d

    i brought a Creative Zen touch today and i'm happy with it. but i can't get the start-up disk to work and this means i can't plug it into my pc. i was wondering how i install the mp3 player to my computer without a working disk ?

  • Getting junk **** mail on iCloud .me .. Can I erase this account

    Erase me account

  • Bug Fix

    Hi all, Is there a fix for the bug 13798847 on oracle 11.2.0.3 . Bug 13798847 : ADD MULTILPLE PORTS TO SCAN_LISTENER FAILS I have searched but dint find anything. Regards, Imran Khan

  • 0 src error message

    I get an error: 0 src is null or not an object code 0 line :291 char: 341 this pops up when i go into yahoo games and click on screen shots. I have updated my java and it stills does this, how can i get this to work I dont want to download a game tha