Пример #1
0
        public void ShowStates(String selectedState)

        {
            var json = new WebClient().DownloadString("https://data.cdc.gov/resource/9mfq-cb36.json");

            //DataTable data = JsonConvert.DeserializeObject<DataTable>(json);
            var result = JsonConvert.DeserializeObject <List <CDCobject> >(json);

            ConvertToDataTable converter = new ConvertToDataTable();

            DataTable data = converter.convertToDataTable(result);
            Calculate obj  = new Calculate();

            DataTable dt = obj.calculate(data);


            DataTable table = obj.getState(selectedState, dt);

            cdcData.DataSource = table;
            cdcData.DataBind();

            int sum = obj.getSum();

            for (int i = 0; i < cdcData.Rows.Count; i++)
            {
                int    num        = Convert.ToInt32(cdcData.Rows[i].Cells[2].Text);
                double percentage = num * 100.0 / sum;
                percentage = Math.Round(percentage, 2);
                cdcData.Rows[i].Cells[3].Text = percentage + " %";
            }
        }
Пример #2
0
        //DataTable temp = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)    // if it's the first page load

            {
                var json = new WebClient().DownloadString("https://data.cdc.gov/resource/9mfq-cb36.json");

                //DataTable data = JsonConvert.DeserializeObject<DataTable>(json);
                var result = JsonConvert.DeserializeObject <List <CDCobject> >(json);

                ConvertToDataTable converter = new ConvertToDataTable();

                DataTable data = converter.convertToDataTable(result);
                Calculate obj  = new Calculate();

                DataTable dt = obj.calculate(data);

                ddlState.DataSource     = dt;
                ddlState.DataTextField  = "state";
                ddlState.DataValueField = "state";
                ddlState.DataBind();

                cdcData.DataSource = dt;

                cdcData.DataBind();
                //temp = dt.Copy();
                int sum = obj.getSum();

                for (int i = 0; i < cdcData.Rows.Count; i++)
                {
                    int    num        = Convert.ToInt32(cdcData.Rows[i].Cells[2].Text);
                    double percentage = num * 100.0 / sum;
                    percentage = Math.Round(percentage, 2);
                    cdcData.Rows[i].Cells[3].Text = percentage + " %";
                }
            }
        }