private void popularNoticias() { PanelNoticias.Visible = true; PanelReadNoticia.Visible = false; using (DataKartDataContext dk = new DataKartDataContext()) { var noticias = (from n in dk.Kart_Noticias_Grupos join u in dk.Usuarios on n.IdUsuario equals u.idUsuario where n.idGrupo == IdGrupo && n.Ativo == true orderby n.dtCriacao descending select new { n.idNoticias, n.IdUsuario, u.Nome, n.Titulo, n.dtCriacao, Noticia = n.Noticia.Substring(0, n.Noticia.Length > 150 ? 150 : n.Noticia.Length) }).Take(50); RptNoticias.DataSource = noticias; RptNoticias.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { HtmlGenericControl tabContact = Master.FindControl("LiDefault") as HtmlGenericControl; tabContact.Attributes.Add("class", "active"); //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://www.mindicador.cl/api"); //using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) //using (Stream stream = response.GetResponseStream()) //using (StreamReader reader = new StreamReader(stream)) //{ // var json = reader.ReadToEnd(); // //DataSet data = JsonConvert.DeserializeObject<DataSet>(json); // DataTable dt = Tabulate(json.ToString()); //} string apiUrl = "https://www.mindicador.cl/api"; string jsonString = "{}"; WebClient http = new WebClient(); JavaScriptSerializer jss = new JavaScriptSerializer(); http.Headers.Add(HttpRequestHeader.Accept, "application/json"); jsonString = http.DownloadString(apiUrl); var indicatorsObject = jss.Deserialize <Dictionary <string, object> >(jsonString); Dictionary <string, Dictionary <string, string> > dailyIndicators = new Dictionary <string, Dictionary <string, string> >(); int i = 0; foreach (var key in indicatorsObject.Keys.ToArray()) { var item = indicatorsObject[key]; if (item.GetType().FullName.Contains("System.Collections.Generic.Dictionary")) { Dictionary <string, object> itemObject = (Dictionary <string, object>)item; Dictionary <string, string> indicatorProp = new Dictionary <string, string>(); int j = 0; foreach (var key2 in itemObject.Keys.ToArray()) { indicatorProp.Add(key2, itemObject[key2].ToString()); j++; } dailyIndicators.Add(key, indicatorProp); } i++; } LblDolar.Text = dailyIndicators["dolar"]["valor"]; LblEuro.Text = dailyIndicators["euro"]["valor"]; LblUf.Text = dailyIndicators["uf"]["valor"]; LblUtm.Text = dailyIndicators["utm"]["valor"]; RptNoticias.DataSource = dal.GetBuscarNoticia(null); RptNoticias.DataBind(); } } catch (Exception ex) { lblInformacion.Text = ex.Message; mdlInformacion.Show(); } }