Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8905129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:18:50+00:00 2026-06-15T02:18:50+00:00

I have a databound dropdownlist on my asp.net page. <asp:DropDownList ID=ddlCases runat=server></asp:DropDownList> I am

  • 0

I have a databound dropdownlist on my asp.net page.

<asp:DropDownList ID="ddlCases" runat="server"></asp:DropDownList>

I am populating ddlCases as

ddlCases.DataSourse = SelectItems();
ddlCases.DataValueField = "itemid";
ddlCases.DataTextField = "itemname";
ddlCases.SelectedIndex = 0;
ddlCases.DataBind();

SelectItems() return a datatable.
What I want to do is to concatenate each item with a sequence number(1,2,3..) in which sequence they appear in the dropdownlist something like
1. itemname1
2. itemname2
3. itemname3

What are my options for achieving this??
Regards,
ZB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:18:51+00:00Added an answer on June 15, 2026 at 2:18 am

    You can do it with linq, something like this should work

    ddlCases.DataSourse = SelectItems().Select((item, index) 
                                                 => new{
                                                         index = index, 
                                                         itemid = item.itemid, 
                                                         itemname = index.ToString() + "." + item.itemname
                                                        });
    ddlCases.DataValueField = "itemid";
    ddlCases.DataTextField = "itemname";
    ddlCases.SelectedIndex = 0;
    ddlCases.DataBind();
    

    EDIT

    Select method creates another IEnumerable(collection) that contains new anonymous type,where index property is index in the first array, itemid is itemid and itemname index + itenmane

    So shortly with LINQ statments we create another temporary class, that contains properties we want

    Hope this make sense

    EDIT

    If SelectItems method returns untyped data table, as @VinayC suggested in the comment you should write

    ddlCases.DataSourse = SelectItems()
    .AsEnumerable().Select((r, i) => new { itemid = r["itemid"], itemname = i.ToString() + r["itemname"] })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search.aspx page that has this: <asp:DropDownList id=ddlPopulation runat=server DataTextField=population DataValueField=pid> </asp:DropDownList>
I have the following mark-up: <asp:DropDownList ID=ddlTownships DataTextField=Name AutoPostBack=True AppendDataBoundItems=True DataValueField=Id runat=server OnSelectedIndexChanged=ddlTownships_SelectedIndexChanged> <asp:ListItem
I have a non-databound Dropdownlist inside of an UpdatePanel: <asp:UpdatePanel runat=server ID=FiltersUpdPnl> <ContentTemplate> <div
I have a DropDownList on an ASP.NET page that gets populated by a SQL
I have a DropDownList called (DDL) in ASP.net page, I want that DDL contains
I have two dropdown lists: <asp:DropDownList ID=Field_Type runat=server /> <asp:DropDownList ID=Field_SubType runat=server /> Field_Type
i have a dropdownlist in a gridview <asp:TemplateField HeaderText=Backup Frequency> <ItemTemplate> <asp:DropDownList ID=DropDownList1 runat=server>
So I have a Web Forms asp control: <asp:DropDownList runat=server ID=ExistingTemplate ClientIDMode=Static /> On
I have a aspx Page where I am using AJAX. like <asp:UpdatePanel runat=server ID=upPanelDDLProgram>
I have asp.net page dropdownlist and button when choose my group from dropdownlist and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.