Hi kid.live,
Please refer below sample.
HTML
<asp:DropDownList ID="ddlBranches" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="OnSelectedIndexChanged">
<asp:ListItem Value="">Select</asp:ListItem>
<asp:ListItem Value="001">Branch 1</asp:ListItem>
<asp:ListItem Value="005">Branch 5</asp:ListItem>
<asp:ListItem Value="006">Branch 6</asp:ListItem>
</asp:DropDownList>
<hr />
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="amount" HeaderText="Amount" />
<asp:BoundField DataField="branch_num" HeaderText="Branch No" />
<asp:BoundField DataField="machineID" HeaderText="Machine" />
<asp:BoundField DataField="shift" HeaderText="Shift" />
<asp:BoundField DataField="userID" HeaderText="User" />
<asp:BoundField DataField="voucher_date" HeaderText="Voucher Date" />
<asp:BoundField DataField="voucher_number" HeaderText="Voucher Number" />
<asp:TemplateField>
<ItemTemplate>
<button class="btn btn-outline-dark rounded-circle">
<i class="bi bi-printer"></i>
</button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Center" CssClass="GridPager" />
</asp:GridView>
<br />
<table>
<tr>
<td>Total Record:-</td>
<td><asp:Label ID="lblTotalRecords" runat="server"></asp:Label></td>
</tr>
</table>
Namespaces
C#
using System.Net
using System.Web.UI.WebControls;
using Newtonsoft.Json;
VB.Net
Imports System.Net
Imports System.Web.UI.WebControls
Imports Newtonsoft.Json
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GetJsonData(string.Empty);
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
this.GetJsonData(ddlBranches.SelectedValue);
}
public void GetJsonData(string branch)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
//string json = (new WebClient()).DownloadString("https://receipt-voucher-default-rtdb.firebaseio.com/receipts.json");
string json = (new WebClient()).DownloadString("https://receipt-voucher-default-rtdb.firebaseio.com/receipts-prod.json");
Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
int noofrecords = values.Count;
List<Receipt> receipts = new List<Receipt>();
foreach (var entry in values)
{
receipts.Add(JsonConvert.DeserializeObject<Receipt>(entry.Value.ToString()));
}
if (!string.IsNullOrEmpty(branch))
{
gvDetails.DataSource = receipts.Where(x => x.branch_num == branch).ToList();
gvDetails.DataBind();
lblTotalRecords.Text = receipts.Where(x => x.branch_num == branch).ToList().Count.ToString();
}
else
{
gvDetails.DataSource = receipts.ToList();
gvDetails.DataBind();
lblTotalRecords.Text = receipts.Count.ToString();
}
}
public class Receipt
{
public string amount { get; set; }
public string branch_num { get; set; }
public string machineID { get; set; }
public string shift { get; set; }
public string userID { get; set; }
public string voucher_date { get; set; }
public string voucher_number { 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.GetJsonData(String.Empty)
End If
End Sub
Protected Sub OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Me.GetJsonData(ddlBranches.SelectedValue)
End Sub
Public Sub GetJsonData(ByVal branch As String)
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
Dim json As String = (New WebClient()).DownloadString("https://receipt-voucher-default-rtdb.firebaseio.com/receipts-prod.json")
Dim values As Dictionary(Of String, Object) = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(json)
Dim noofrecords As Integer = values.Count
Dim receipts As List(Of Receipt) = New List(Of Receipt)()
For Each entry In values
receipts.Add(JsonConvert.DeserializeObject(Of Receipt)(entry.Value.ToString()))
Next
If Not String.IsNullOrEmpty(branch) Then
gvDetails.DataSource = receipts.Where(Function(x) x.branch_num = branch).ToList()
gvDetails.DataBind()
lblTotalRecords.Text = receipts.Where(Function(x) x.branch_num = branch).ToList().Count.ToString()
Else
gvDetails.DataSource = receipts.ToList()
gvDetails.DataBind()
lblTotalRecords.Text = receipts.Count.ToString()
End If
End Sub
Public Class Receipt
Public Property amount As String
Public Property branch_num As String
Public Property machineID As String
Public Property shift As String
Public Property userID As String
Public Property voucher_date As String
Public Property voucher_number As String
End Class
Screenshot