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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:00:28+00:00 2026-05-27T03:00:28+00:00

I recently was assigned to update an old project who use the asp:listbox control

  • 0

I recently was assigned to update an old project who use the asp:listbox control (which I’m not very good at handling).

The set up is that the ListBox is placed on a aspx.page and fills itself with data through the DataSource attribute.
The columns database table populating the ListBox is activity_points (datatype float) and activity_title (datatype string / varchar).
The ListBox gets filled out and everything looks fine until i check whats in the value of the list items.

The ListBox looks as follows

<asp:ListBox runat="server" DataSource="<%# GetActivitys(1) %>" DataTextField="activity_title"
DataValueField="activity_points" EnableViewState="true" onchange="DataChanged();SumUpRow(this,true);"
Width="200" CssClass="ddl-activity1" ID="activities_1_1" Rows="1" />

The default method (which I inherited) looks like this

public SqlDataReader GetActivitys(int type)
{
    SqlConnection conn = new SqlConnection(umbraco.GlobalSettings.DbDSN);
    SqlCommand cmd = new SqlCommand("SELECT * FROM " + DATABASE_TABLE_ACTIVITIES + " WHERE activity_type=" + type.ToString() + " ORDER BY activity_type, activity_sortorder, activity_title", conn);
    cmd.Connection.Open();
    return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}

The generated list items look like this

<option value="6">testing</option>
<option value="9">testing</option>
<option value="6,5">testing</option>
<option value="5">testing</option>
<option value="7">testing</option>
<option value="4,5">testing</option>
<option value="6.0">testing</option>
<option value="4">testing</option>
<option value="3.0">testing</option>
<option value="6.00">testing</option>
<option value="3,5">testing</option>
<option value="6.000">testing</option>

As clearly seen it mixes points and commas, and it adds a zero after each occurrence if the same value is repeated. If I render the same result set to a GridView everything looks fine!

Just to ensure that the data returned from the database is correct I’ve created a new method that converts the activity_points column

public DataTable GetActivitys(int type)
{
    string query = "SELECT activity_points, activity_title, activity_id FROM " + DATABASE_TABLE_ACTIVITIES + " WHERE activity_type=" + type.ToString() + " ORDER BY activity_type, activity_sortorder, activity_title";
    SqlConnection conn = new SqlConnection(umbraco.GlobalSettings.DbDSN);
    SqlDataAdapter da = new SqlDataAdapter(query, conn);
    DataTable dt = new DataTable();
    da.Fill(dt);

    /**/

    DataTable dtActivity = new DataTable();
    DataColumn ActivityCol;

    ActivityCol = new DataColumn();
    ActivityCol.DataType = Type.GetType("System.String");
    ActivityCol.ColumnName = "activity_points";
    dtActivity.Columns.Add(ActivityCol);

    ActivityCol = new DataColumn();
    ActivityCol.DataType = Type.GetType("System.String");
    ActivityCol.ColumnName = "activity_title";
    dtActivity.Columns.Add(ActivityCol);

    ActivityCol = new DataColumn();
    ActivityCol.DataType = Type.GetType("System.Int32");
    ActivityCol.ColumnName = "activity_id";
    ActivityCol.Unique = true;
    dtActivity.Columns.Add(ActivityCol);


    foreach (DataRow item in dt.Rows)
    {
        DataRow activityRow = dtActivity.NewRow();
        activityRow["activity_points"] = Convert.ToDouble(item["activity_points"]);
        activityRow["activity_title"] = item["activity_title"];
        activityRow["activity_id"] = item["activity_id"];

        dtActivity.Rows.Add(activityRow);
    }

    return dtActivity;
}

Im running out of options, is there something magic about ListBoxes that I missed?

Any advice is highly appreciated!

Thanks

  • 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-05-27T03:00:29+00:00Added an answer on May 27, 2026 at 3:00 am

    Appears as if the listbox values always gets an incremental value of an integer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I was assigned to a project which was already in its midway. It
I have recently been assigned a CSS & design project that's in a CakePHP
Recently I just got assigned a project to develop a web application/site that uses
Recently I was asked to develop an app, which basically is going to use
I'm very much new to Test Automation kind of thing. Recently I've been assigned
I have been recently assigned a task in which I need to create a
In a project at work, I've recently been assigned to encode the user input
I recently started a new project using Automatic Reference Counting (ARC). When I assigned
I've recently been assigned to a C++ project involving information being sent between computers
Recently I've been assigned a bug to fix, which from my point of view,

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.