gridview is not showing data properly - asp.net

while trying to get data from https://blockchain.info/ticker in my grid view, i'm finding the result in single coloumn whether i want it in different coloumn.
i'm showing you my code and please give me a soloution.
public void ticker()
{
WebClient webClient = new WebClient();
dynamic result =webClient.DownloadString("https://blockchain.info/ticker");
GridView1.DataSource = result;
GridView1.DataBind();
}
[https://i.stack.imgur.com/nPjgS.jpg]

It looks like your results in JSON format so you have to convert in the proper format to display well in GridView.
import Newtonsoft.Json
dynamic result =JsonConvert.DeserializeObject(
webClient.DownloadString("https://blockchain.info/ticker"));
I hope it's help you, you can search more about it
thanks

Related

System.OutOfMemoryException with JSON.NET

Tried this with JSON.NET 6.0
DataSet ds = Newtonsoft.Json.JsonConvert.DeserializeObject<DataSet>
("{\"tab1\":[{\"col1\":\"val1\"}]}"); // OK
DataTable dt = Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>
("{\"col1\":\"val1\"}"); // System.OutOfMemoryException
why?
thank you
IMO it's a bug, But if you want to deserialize DataSet or DataTable this might help you.
The JSON in your second example represents a only a single row of data, not a DataTable. A DataTable is an ordered collection of DataRows, therefore it needs to have square brackets in the JSON. Try it like this instead:
string json = "[{\"col1\":\"val1\"}]";
DataTable dt = JsonConvert.DeserializeObject<DataTable>(json);
I am not sure why you are getting an OutOfMemoryException; I get a JsonSerializationException when I try it, as I would expect. Perhaps this was a bug that was fixed in the most recent version of Json.Net.
I have over come with this issue by creating JsonSerializer object. My code is as given below.
using (StreamReader r = new StreamReader(yourfilePath))
{
using (JsonReader reader = new JsonTextReader(r))
{
JsonSerializer serializer = new JsonSerializer();
T lstObjects = serializer.Deserialize<T>(reader);
}
}
Here yourfilePath :- is your file current full path
T :- is your object name, whether it could be Dataset, DataTable or any custom Object.

Data Format Error in Asp.net

I want to set my Salary field value into $23,000.00 and send that value into my database ,i created below code inside my model class but it has some errors need some one help to fix that errors,I am new to Asp.net MVC4 Please help me to solve that problems.
when i save data it goes to database like that way- $23000
but actually i want to send like that way -$23,000.00
when i view my results in my view page it seems $$23000
But i want that way - $23,000.00
Please help me to solve that problems.
Thanks .
public string Salary
{
get
{
return SalaryFormat;
}
set
{
StringBuilder sb = new StringBuilder();
SalaryFormat = Convert.ToString(sb.AppendFormat("${0: #,###.00}", value));
//SalaryFormat = value;
}
}
Thanks!

How to Load GridView/Repeater Data On Scrolling the page/Paging in ASP.NET like Facebook?

I have a GirdView which has more than thousands of records binded to it. I have applied the Paging for GirdView whenever we traverse the paging the request is sent again to Server and whole data is loaded into GridView from SQLServer DB, which I want to avoid Server Round Trip. Is it possible to Load Data First 100 Number of Records and then 101 to 200 and so on..Records when Scrolling the Grid or Paging from DataTable or DataSet?
Similar to Facebook loads Data on the Page only when the User Scrolls down the page. Is it possible to do in ASP.NET using C#?
Please Give me suggestion
Convert DataTable to json format :
public static string DataTableToJSON(DataTable table)
{
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (DataRow row in table.Rows)
{
Dictionary<string, object> dict = new Dictionary<string, object>();
foreach (DataColumn col in table.Columns)
{
dict[col.ColumnName] = row[col];
}
list.Add(dict);
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(list);
}
Yes it is possible however fairly convoluted. You may be better off using one of the Javascript model binding frameworks (Backbone/KnockoutJs) to implement this.
If you do want to however, you'd need to put your GridView inside an UpdatePanel and then listen to the window scroll event in Javascript and each time the event is fired rebind the GridView datasource.
Use Custom paging for the purpose and while fetching the data from the database use skip and take in your query.

Error in ASP.NET C# (implicit conversion)

I am new in ASP.NET programming. Please help me.
void DisplayData()
{
DataTable dt = new DataTable();
//objBuyer.BuyerId = Convert.ToInt64(Request.QueryString["id"]);
**ERROR-->>>** dt = objBuyer.DisplayData();********
if (dt.Rows.Count > 0)
{
txtBName.Text = dt.Rows[0][1].ToString();
ERROR:Cannot implicitly convert type 'void' to 'System.Data.DataTable'
You are trying to convert void to a DataTable, which is not possible. Your method has to return a DataTable for this to work.
The problem is that the DisplayData method does not return a DataTable object, it simply displays the data in objBuyer, and returns void.
That's the problem, but I can't really help further than that without some sort of context!
The DisplayData() method needs to return a DataTable in order for this to work.
A nice and easy tutorial can be found here: http://www.aspnettutorials.com/tutorials/controls/data-table-csharp.aspx
As you can see, there's a DataTable created and after that's done, several rows are added to the table with the Rows.Add() method.

JSON.NET with GridView

I am trying to find a way bind Grid view to a JSON.NET parsed Linq to Json object
simply am calling
JObject yrs = SearchData("");
then use one property to be bound to Grid view
GridView1.DataSource = yrs["businesses"].Children();
I cant find any resources for something like that
neither binding directly work nor using Children, and seems like I can not find it in the documentation.
appreciate your help
I think I just needed to sleep :)
this is how it should go, if someone need that ,
var bsn =from c in yrs["businesses"].Children()
select new { Title = (string)c["Title"] , Type = (string)c["Type"] };
GridView1.DataSource = bsn;
if there are better ways please advice

Resources