Hi kid.live,
Please refer below sample.
HTML
<table>
<tr>
<td>Branch Number:</td>
<td><asp:TextBox runat="server" ID="txtBranchNumber" /></td>
</tr>
<tr>
<td>Machine Number:</td>
<td><asp:TextBox runat="server" ID="txtMachineNumber" /></td>
</tr>
<tr>
<td><asp:Button Text="Search" runat="server" OnClick="Search" /></td>
</tr>
</table>
<hr />
<asp:GridView runat="server" ID="gvDetails">
</asp:GridView>
Namespaces
C#
using System.Data;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
VB.Net
Imports System.Data
Imports System.Net
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindData();
}
}
protected void Search(object sender, EventArgs e)
{
this.BindData();
}
private void BindData()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
string json = (new WebClient()).DownloadString("https://fuel-station-d8853-default-rtdb.firebaseio.com/invoices-prod.json");
JToken result = JsonConvert.DeserializeObject("[" + json + "]") as JToken;
List<Root> roots = new List<Root>();
foreach (var item in result)
{
JObject obj = JObject.Parse(item.ToString());
foreach (var keypair in obj)
{
foreach (var keypair1 in JObject.Parse(keypair.Value.ToString()))
{
foreach (var item1 in JObject.Parse(keypair1.Value.ToString()))
{
roots.Add(JsonConvert.DeserializeObject<Root>(item1.Value.ToString()));
}
}
}
}
if (!string.IsNullOrEmpty(txtBranchNumber.Text) || !string.IsNullOrEmpty(txtMachineNumber.Text))
{
roots = roots.Where(x => x.branch_num.StartsWith(txtBranchNumber.Text.Trim()) && x.machineID.StartsWith(txtMachineNumber.Text.Trim())).ToList();
}
gvDetails.DataSource = roots;
gvDetails.DataBind();
}
public class Root
{
public string branch_num { get; set; }
[JsonProperty("date")]
public DateTime _date { get; set; }
public string invoice_number { get; set; }
public string item { get; set; }
public string machineID { get; set; }
public string payment_type { get; set; }
public double price { get; set; }
public double qty { get; set; }
public double total { get; set; }
public string userID { get; set; }
public double vat_amount { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindData()
End If
End Sub
Protected Sub Search(ByVal sender As Object, ByVal e As EventArgs)
Me.BindData()
End Sub
Private Sub BindData()
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
Dim json As String = (New WebClient()).DownloadString("https://fuel-station-d8853-default-rtdb.firebaseio.com/invoices-prod.json")
Dim result As JToken = TryCast(JsonConvert.DeserializeObject("[" & json & "]"), JToken)
Dim roots As List(Of Root) = New List(Of Root)()
For Each item In result
Dim obj As JObject = JObject.Parse(item.ToString())
For Each keypair In obj
For Each keypair1 In JObject.Parse(keypair.Value.ToString())
For Each item1 In JObject.Parse(keypair1.Value.ToString())
roots.Add(JsonConvert.DeserializeObject(Of Root)(item1.Value.ToString()))
Next
Next
Next
Next
If Not String.IsNullOrEmpty(txtBranchNumber.Text) OrElse Not String.IsNullOrEmpty(txtMachineNumber.Text) Then
roots = roots.Where(Function(x) x.branch_num.StartsWith(txtBranchNumber.Text.Trim()) AndAlso x.machineID.StartsWith(txtMachineNumber.Text.Trim())).ToList()
End If
gvDetails.DataSource = roots
gvDetails.DataBind()
End Sub
Public Class Root
Public Property branch_num As String
<JsonProperty("date")>
Public Property _date As DateTime
Public Property invoice_number As String
Public Property item As String
Public Property machineID As String
Public Property payment_type As String
Public Property price As Double
Public Property qty As Double
Public Property total As Double
Public Property userID As String
Public Property vat_amount As Double
End Class
Screenshot