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 9016973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:08:38+00:00 2026-06-16T04:08:38+00:00

I create one datalayer method public static List<SegmentBL> GetAllSegment(string SortDirection, string SortExpression) { var

  • 0

I create one datalayer method

  public static List<SegmentBL> GetAllSegment(string SortDirection, string SortExpression)
    {

        var ds = DBHelper.GetDatabase().ExecuteDataSet("UDS_Select_SegmentMaster");

        var val = ds.Tables[0].AsEnumerable().Select(r => new SegmentBL
        {
            _SegmentId = Convert.ToInt32(r[0].ToString()),
            _SegmentName = r[1].ToString()
        });
        List<SegmentBL> list = val.ToList();
        return list;
    }

from that I create one Bussiness logic method

public DropDownList GetAll(string SortDirection, string SortExpression)
    {
        var list = new DropDownList();
        list.DataSource = SegmentDL.GetAllSegment(SortDirection, SortExpression);
        list.DataTextField = "_SegmentName";
        list.DataValueField = "_SegmentID";
        list.DataBind();
        ListItem item = new ListItem();
        item.Text = "--Select--";
        item.Value = "0";
        list.Items.Insert(0, item);
        return list;
    }

Finally Presentation Layer Method for filling dropdownlist

 private void FillSegment()
    {
        ddlSegment.DataSource = seg.GetAll(General.SortAscending,"SegmentID").Items;

        ddlSegment.DataBind();
        ddlSegment.DataTextField = "_SegmentName";
        ddlSegment.DataValueField = "_SegmentID";
    }

It’s working fine except the DataTextField and DataValueField not assign properly. Currently DataTextField and DataValueField same. What is mistake I did in above code.

  • 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-16T04:08:39+00:00Added an answer on June 16, 2026 at 4:08 am

    You are binding before the elements are added to the datasource bind after the elements being added. You may pass dropdownlist to your method intead of creating local drop down in GetAll method.

    public DropDownList GetAll(string SortDirection, string SortExpression, DropDownList list)
    {
      //  var list = new DropDownList(); //Remove this line
        list.DataSource = SegmentDL.GetAllSegment(SortDirection, SortExpression);
        list.DataTextField = "_SegmentName";
        list.DataValueField = "_SegmentID";      
        ListItem item = new ListItem();
        item.Text = "--Select--";
        item.Value = "0";
        list.Items.Insert(0, item);
        list.DataBind();
        return list;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create one drop down list contains some Languages. By selecting any
i want create one simple windows form ,it just contain Editcontrol(textbox),Static Edit(label),Button (Name of
How to create one array in a method with user given length? I would
i am customize telerik Datapager control in that control create one resource file and
I create one example in Android 3.0 and I use the fragment in it.
I create one table by using jquery : <div class=productlist style=float:left; id=productlist> <script type=text/javascript
I want to create one new model class, which will be extended in all
I want to create one proc like below but it has error on syntax.
I have to create one table using XSLT and CSS. The table should look
Basically I want to create one large object of many object in JavaScript. Something

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.