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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:28:50+00:00 2026-06-10T18:28:50+00:00

I am using c# asp.net and c# where i try to filter an amchart

  • 0

I am using c# asp.net and c# where i try to filter an amchart using a dropdown listbox. But no matter what i select i get the value f the first element, I tried !ispostback, but no luck,
The following is the frontend code,

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default"  EnableEventValidation = "false" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

    <head>


        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>amCharts examples</title>
        <link rel="stylesheet" href="http://localhost/style1.css" type="text/css">
        <script src="http://localhost/amcharts.js" type="text/javascript"></script>         
        <script type="text/javascript">

            var chart;

            var chartData = JSON.parse('<%=sjson%>'); 

            AmCharts.ready(function () {
                // SERIAL CHART
                chart = new AmCharts.AmSerialChart();
                chart.dataProvider = chartData;
                chart.categoryField = "Ip";
                chart.startDuration = 1;

                //scrollbar definition
                var chartScrollbar = new AmCharts.ChartScrollbar();

                // AXES
                // category
                var categoryAxis = chart.categoryAxis;
                categoryAxis.labelRotation = 90;
                categoryAxis.gridPosition = "Count";

                // value
                // in case you don't want to change default settings of value axis,
                // you don't need to create it, as one value axis is created automatically.

                // GRAPH
                var graph = new AmCharts.AmGraph();
                graph.valueField = "Count";
                graph.balloonText = "[[category]]: [[value]]";
                graph.type = "column";
                graph.lineAlpha = 0;
                graph.fillAlphas = 0.8;

                //add scrollbar to graph
                chartScrollbar.graph = graph;
                chartScrollbar.scrollbarHeight = 40;
                chartScrollbar.color = "#000000";
                chartScrollbar.autoGridCount = true;
                chart.addChartScrollbar(chartScrollbar);

                chart.addGraph(graph);

                chart.write("chartdiv");
            });
        </script>

    </head>

    <body>
        <form id="form1" runat="server">
        <div id="chartdiv" style="width: 100%; height: 400px;"></div>
        <div>
            <asp:DropDownList ID="DropDownListISP" runat="server" AutoPostBack="True" 
                onselectedindexchanged="DropDownListISP_SelectedIndexChanged">
            </asp:DropDownList>
        </div>
        </form>
    </body>

</html>

And following is my code behind,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using MySql.Data.MySqlClient;
using System.Data;

public partial class Default : System.Web.UI.Page
{
    public string sjson;
    string connStr = "server=localhost;Database=db_tav;Uid=root;Pwd=pass;";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) { 
            populateList();
            filterData("etisalat");
        }

    }
    private void populateList() {
        MySqlConnection connPopulate = new MySqlConnection(connStr);

        connPopulate.Open();
        MySqlCommand cmd = new MySqlCommand();

        cmd = connPopulate.CreateCommand();
        cmd.CommandText = "SELECT DISTINCT isp FROM tbl_correlateTest WHERE isp !=''";//

        MySqlDataReader ddlValues;
        ddlValues = cmd.ExecuteReader();

        DropDownListISP.DataSource = ddlValues;
        DropDownListISP.DataValueField = "isp";
        DropDownListISP.DataTextField = "isp";
        DropDownListISP.DataBind();

        connPopulate.Close();
        cmd.Connection.Close();
        cmd.Connection.Dispose();
    }
    private void filterData(string isp) {
        MySqlConnection conn = new MySqlConnection(connStr);

        conn.Open();

        MySqlCommand cmd = new MySqlCommand();

        cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT IP, conLvl FROM tbl_correlateTest WHERE isp LIKE ?ispVal order by ip asc";//
        cmd.Prepare();
        cmd.Parameters.Add("?ispVal", MySqlDbType.VarChar, 100).Value = "%" + isp + "%";
        MySqlDataReader readIp = cmd.ExecuteReader(CommandBehavior.CloseConnection);

        ArrayList conRc = new ArrayList();

        while (readIp.Read())
        {
            string ipVal = readIp.GetString(0);
            string conLvlVal = readIp.GetString(1);
            conRc.Add(new Confidence(ipVal, conLvlVal));

        }

        System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        sjson = oSerializer.Serialize(conRc);

        conn.Close();        
    }
    protected void DropDownListISP_SelectedIndexChanged(object sender, EventArgs e)
    {
        string isp = DropDownListISP.SelectedValue.ToString();
        isp = isp.Trim();
        filterData(isp);
    }

}

PLEASE help me on this one, i tried everything i can but this listbox always returns the first value 🙁 thank you very much.. 🙂


EDIT:

I can retrieve the selected item value if i perform the following instead of data bind.

    MySqlDataReader readIsp = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    while (readIsp.Read())
    {
        string ispVal = readIsp.GetString(0);
        ispVal = ispVal.Trim();
        DropDownListISP.Items.Add(ispVal);

    }

any idea what the issue is?? just for information.. 🙂

  • 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-10T18:28:51+00:00Added an answer on June 10, 2026 at 6:28 pm

    If binding the data is raising the issue and adding the items is not, than it means that populateList is being called, and when dropdown is binded again, previous selection is washed out. Put a break point in the populateList method and see if it gets hit when you do a post back from dropdown.

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

Sidebar

Related Questions

I am using asp.net membership and trying to update a users details but get
Let me try to set the scenario here first. This is done using ASP.NET
I'm using ASP.Net and whenever I create a script file or try to include
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
I'm using ASP.NET MVC 1.0 and I try to create a personal blog! I
I'm using ASP.NET MVC 3 with the Entity Framework 4 code first approach and
I'm using the Northwind database, to try to understand the WebAPI for Asp.Net. My
I'm using asp.net global resource to try and implement a two language website, I
I'm using asp.net and c#, making a page with ajax updatepanels. When I try
I am using ASP.Net 4.0 with MVC 3 and C# to try and send

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.