0

So I have a web application and I am trying to modify a value from the JSON object and then to display it.

However currently, once I have modified (formatted the time) and attempt to display it, the old value is being displayed - i.e the value from the JSON object.

Can't seem to figure out how to 'save' my changes.

My .apsx code is:

    <asp:Repeater ID="Repeater_weatherReports" runat="server" onitemcommand="reptrData_ItemCommand">
        <ItemTemplate>
            <table id="tblWeather" border="0" visible="true">
                   <td>
                        **date:<asp:Label runat="server" ID="DateWeather" Text='<%# Eval("dt") %>' />&nbsp;**
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:Repeater>

My C# code :(simplified)

public partial class _Default : System.Web.UI.Page
{

    //string city_name;
    string temp_min;
    string temp_max;
    string humidity;
    DateTime weatherdate;



    protected void reptrData_ItemCommand(object source, RepeaterCommandEventArgs e)
    {


        Label LblDate = e.Item.FindControl("DateWeather") as Label;
       // weatherdate = LblDate.Text;


    }



    protected void GetWeatherInfo(object sender, EventArgs e)
    {




        using (WebClient client = new WebClient())
        {
            string json = client.DownloadString(url);

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            WeatherInfo weatherinfo = serializer.Deserialize<WeatherInfo>(json);

            Repeater_weatherReports.DataSource = weatherinfo.list;
            Repeater_weatherReports.DataBind();





            foreach (List list in weatherinfo.list)
            {


                if (list != null)

                {

                    //var weatherdate = TimeSpan.FromSeconds(list.dt);

                    **var weatherdate = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(list.dt);**




                    temp_min = string.Format("{0}", Math.Round(list.temp.min, 1));
                    temp_max = string.Format("{0}", Math.Round(list.temp.max, 1));
                    humidity = list.humidity.ToString();

                }




            }





        }
    }


    public class Coord
    {
        public double lon { get; set; }
        public double lat { get; set; }
    }

    public class City
    {
        public int id { get; set; }
        public string name { get; set; }
        public Coord coord { get; set; }
        public string country { get; set; }
        public int population { get; set; }
    }

    public class Temp
    {
        public double day { get; set; }
        public double min { get; set; }
        public double max { get; set; }
        public double night { get; set; }
        public double eve { get; set; }
        public double morn { get; set; }
    }

    public class Weather
    {
        public int id { get; set; }
        public string main { get; set; }
        public string description { get; set; }
        public string icon { get; set; }
    }

    public class List
    {
        public int dt { get; set; }
        public Temp temp { get; set; }
        public double pressure { get; set; }
        public int humidity { get; set; }
        public IList<Weather> weather { get; set; }
        public double speed { get; set; }
        public int deg { get; set; }
        public int clouds { get; set; }
        public double? rain { get; set; }
    }

    public class WeatherInfo
    {
        public City city { get; set; }
        public string cod { get; set; }
        public double message { get; set; }
        public int cnt { get; set; }
        public IList<List> list { get; set; }
    }

}

So i am converting the UNIX date into a normal date. However only the UNIX date is still being displayed. Any help would be appreciated, thanks

edit - extra c# code:

public partial class _Default : System.Web.UI.Page
{

    //string city_name;
    string temp_min;
    string temp_max;
    string humidity;
    DateTime weatherdate;


    protected void Page_Load(object sender, EventArgs e)
    {

    }




    protected void reptrData_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        //Label lblCity = e.Item.FindControl("lblCity_Country") as Label;
        //city_name = lblCity.Text;

        Label lblHumidity = e.Item.FindControl("Label_humidity") as Label;
        humidity = lblHumidity.Text;

        Label LblMin = e.Item.FindControl("Label_min") as Label;
        humidity = lblHumidity.Text;

        Label LblMax = e.Item.FindControl("Label_max") as Label;
        temp_max = lblHumidity.Text;

        Label LblDate = e.Item.FindControl("DateWeather") as Label;
        weatherdate = Convert.ToDateTime(LblDate.Text);


    }
5
  • You are populating weatherdate but I can't see any code that reads from it. Can you include that code in your post? Commented Aug 13, 2017 at 13:45
  • What happens if you change var weatherdate to weatherdate? Commented Aug 13, 2017 at 13:45
  • You are changing the value after the databind, that’s too late Commented Aug 13, 2017 at 14:23
  • I've added some more code in my original post. I am reading the values from the labels at the code of my code. Your right though, I had declared var weatherdate but not read it in. Im not sure how I can link the value from the Json object though in order to format the time, and the output it. Commented Aug 13, 2017 at 14:37
  • changing var weatherdate, to just weather date did not solve it. Same output (the unformatted timestamp in UNIX) Commented Aug 13, 2017 at 14:38

1 Answer 1

1

You are binding data source before updating it.See below regions specified

#region dataBind
 Repeater_weatherReports.DataSource = weatherinfo.list;
            Repeater_weatherReports.DataBind();
#endregion
#region dataChange
            foreach (List list in weatherinfo.list)
------
#endregion

Bind data after manipulation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.