.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Sort list in dropdownlist

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :SharePoint


I have created a custom list in sharepoint and then I created a dropdown col (as lookup) to use that list.

All I want items in the dropdownlist to be appeared in sort order. How can I do that.

Any suggestions! Thanks

View Complete Post

More Related Resource Links

Need to remove databinding of DropdownList when another dropdown list changes


I have many controls on my form, but in particular, I have 2 dropdownlists.  1 dropdown list has 2 values, and each value controls what the second dropdownlist displays.  This is an edititemtemplate and both dropdowns have the selecteditem set via '<%# Bind("fieldname") #>' on page load.  

THe problem is, if I change the value of the first dropdown, it errors out because the second dropdwon has a bound value that is no longer acceptable. 

Can I cancel the bind of the second control, if the the first one is changed?  I would like to cancel the bind, and update the values by using a different datasource depending on the value of the first dropdown or hardcode the new values.



If Dropdown1 has a value of "A" for example Dropdown 2 Shows Values "1", "2", "3"

If Dropdown 1 has a value of "B" , Dropdown2 Shows Values "4", "5", "6".

It binds fine initially, but if I change Dropdown1 from A to B, I want Dropdown2 to show the new values, maybe with a default of "Select an Item" and not error out b/c it's attempts to bind a value of 1, 2, or 3.


Hope this makes sence, b/c I'm

.Sort a List problem



I have a little problem with sorting a List<String>.

I have put 4 elements like this and now are trying sort them correct. My example below shows the problem. I am not sure of how sort the names so they comes in this order: "Folder1, Folder2, Folder10, Foler11"  ?

List<String> GetNames = new List<String>();

GetNames .Add("Folder1");
GetNames .Add("Folder10");
GetNames .Add("Folder2");
GetNames .Add("Folder11");

GetNames.Sort(); //Sort the list

The sort comes in this order now which is wrong:

How to sort the list to have this order: ?



ListItem Dynamic DropDownList based on custom list entries.

I utilized the following solution to get the drop down list on the page and populate it dynamically, but it doesn't save the selected value back to the SPListItem object. Does anyone have a better solution possibly for this? http://geekswithblogs.net/SoYouKnow/archive/2010/01/21/sharepoint-populating-drop-down-list-field-with-data-from-different.aspx

How to Sort a List

Hi, I have  aList<String> with textFiles. I wonder how it is possible to sort this List<String> so the  textFiles gets in order starting with the lowest number to the highest number. Now the order is like this and below the example is the sorted order I after to achieve: ( .Sort() does not sort it in this order)List<String> Listing = new List<String>(); Listing.Add("1.txt"); Listing.Add("23.txt"); Listing.Add("12.txt"); Listing.Add("3.txt"); Listing.Add("2.txt"); //Sort so the above list have this order ? Listing.Add("1.txt"); Listing.Add("2.txt"); Listing.Add("3.txt"); Listing.Add("12.txt"); Listing.Add("23.txt");    

How do you sort the library list under "Document Library" ?

How do you sort the library list under "Document Library" ? I am using SharePoint Service 2007. So far my SharePoint page is still mostly default and haven't gone far yet. The library LIST under Document Library, named "Document" are all not in order. It just keep adding to the last one in list. I am not talking about the folders or files under each library. I am talking about the Library list on the left hand top side below the section called "Documents". I can't find a way to sort it..... HELP    

How to bind a List of hybriddictionay to the dropdownlist

I have a List<HybridDictionary> _Reasons.I need to bind the list to a dropdown. I tried the code as try            {                this.ddlReason.DataSource = _Reasons;                ddlReason.DataValueField = "Key";                ddlReason.DataTextField = "Value";                this.ddlReason.DataBind();                           }            catch            {                //Log Entry            }            finally            {             } But it not work.Please sugges

Html.DropDownList using a List

This has to be a simple thing, but for whatever reason, I'm just not finding it. I want to use the HTML Helper function to create a DropDownList based on a List<string> (and actually have it bind to the data field on the model).  The simplest example, I suppose, would be: <%: Html.DropDownList("Material", new SelectList(new[] {"Wood","Brick","Metal"})) %> This creates the items in the drop-down, but of course, there's nothing in this line that would bind it to my model (model.Material).  I've done drop-downs with collections of models, where you can bind the Data and Display attributes to properties of the class, but I don't have a class here, just a List. Any ideas?

'Dropdownlist' has a SelectedValue which is invalid because it does not exist in the list of items


I have a dropdown list that has a bind on it and I get this error. Why am I getting this error and what can I do to fix it. here is the code for the dropdown I currently have:


 <asp:DropDownList  ID="DDLPreferred" AppendDataBoundItems="true" SelectedValue='<%# Bind("PREFERRED_COMMUNICATION") %>'  runat="server" TabIndex="15">
                <asp:ListItem Text="none" Value=""></asp:ListItem>

				<asp:ListItem>Home Phone</asp:ListItem>
				<asp:ListItem>Work Phone</asp:ListItem>
				<asp:ListItem>Cell Phone</asp:ListItem>


How to add a sub-list to dropdownlist control



I have question about dropdownlist control.

I have a dromdownlist control which shows the list of dealers. I want to
add a sub-list to each dealer which should populate the products available at
that particular dealership. I don't want to select value from sub-list. Just want to display.

Thanks alot


DropDownList error message: "value not found in the list"


Inside a FormView control, I have a DropDownList that populates a SQL column with city names. The SQL column type is nchar(50) -- I set it for 50, since the city names can be short or very long. The DropDownList contains all the city names. When a new record is created in SQL via this FormView control, the DropDownList successfully populates the column cell.

However, when I try to edit that record (using the edit template in FormView), I get the above error message...I believe the retrieved entry is not matching the entry in the list, because SQL isn't just storing the number of characters that a given city has (say "6" for Boston), it is storing/retrieving 50 characters (6 + 44 null spaces = 50 characters)--and thus DropDownList doesn't recognize that the entry is just "Boston"...How can I resolve? How can I ensure that there are no extra spaces recorded in a SQL cell beyond what is needed to accomodate the name of any given city?  Is this a SQL task or can it be resolved in ASP.NET?  Thank you. 

DropDownList - Selected Value not in List Error.


If you use a dropdownlist and the selected value for the ddl is not in the datasource.  This can happen in an existing record if the user changes the datasource, e.g. deletes a row.  ASP.net throws an exception.

To get around this problem, you can not bind the SelectedValue in the aspx page and use code like the following in the FormView_DataBound Event. 

'-- Set DropDownList - Selected Value
      If Me.FormView1.CurrentMode = FormViewMode.Edit Then
         Dim ddl1 As DropDownList = Me.FormView1.FindControl("ddlTest")
         If Not IsDBNull(ddlTest) Then
            Dim strValue As String = (DataBinder.Eval(FormView1.DataItem, "DataFIeldName").ToString())
            If ddl1.Items.IndexOf(ddl1.Items.FindByValue(strValue)) >= 0 Then
               ddl1.SelectedValue = DataBinder.Eval(FormView1.DataItem, "DataFieldName")

Dropdownlist error: SelectedValue which is invalid because it does not exist in the list of items.


I have a dropdownlist in a detailsview edit Item template. Also I have two tables - Employee and Main. In the Employee table I have column EmpId and AssignedTo. In the main table I have EmpId which is connected to the Employee table. 

The detailsView has a label which shows the AssignedTo name for a particular record and it works fine. But if I click the edit button to shwo the dropdownlist in the editItemTemplate it is givig me the above error.

The code is:

<asp:DetailsView ID="dtvAssign" runat="server" AutoGenerateRows

How to get list of VALUES (not items) from a dropdownlist?


Hello all.  I see that dropdownlist has an "items" property to get the list of displayed items for a dropdown, but it doesn't seem to have an equivalent property for getting the "values" associated with the items.  For example, I may have a dropdown that displays "High", "Medium" and "Low", but returns values of "H", "M", "L".  How can I easily get that list of HML?

Thanks for any help!


Infopath 2007 Repeating Sharepoint List Sort Auto Number


Infopath 2007
Browser Enabled
Sharepoint List in a Repeating table

I have a view with a Sharepoint List showing in a repeating table. I have conditional formatting to hide items that should not show based on Line Total.

Line Total = 4

Approver    Min Amount        Max Amount  
Jim                      3                  9
Jack                    1                   7
Sally                   2                    5

Based on this, I need to sort the Approvers based on Max Amount and send an email to them in order of the sort.  Is this possible?


dropdownlist to sort (ASC/DESC) in Listview



Someone who can help me make a sort (asc / desc) in my ListView through a dropdownlist ?


Sharepoint 2007 list troubles: IP fields and sort by IP


Help! I've created text fields that have IP's but they do not get sorted right.


I know this is correct sort for normal text. Do anybody have any clue of how I can use IP's in Sharepoint 2007 lists?

Urgent!!!How can we sort the parameter list in report created using report model in ssrs 2008 r2?


How can we sort the parameter list in report created using report model in ssrs 2008 r2? Do I need to change some property in Model or elsewhere?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend