Can You Help Me In Sorting? How Can I Add Sorting?
<asp:GridView runat="server" CssClass="table table-striped table-bordered" AutoGenerateColumns="false"
Width="100%" ID="gvInvoices">
<Columns>
<asp:BoundField DataField="branch_num" HtmlEncode="false" HeaderText="رقم المحطة<br/>Branch No" />
<asp:BoundField DataField="_date" HtmlEncode="false" HeaderText="التاريخ<br/>Date" />
<asp:BoundField DataField="invoice_number" HtmlEncode="false" HeaderText="رقم الفاتورة<br/>Invoice No" />
<asp:BoundField DataField="item" HtmlEncode="false" HeaderText="الصنف<br/>Gasoline Type" />
<asp:BoundField DataField="machineID" HtmlEncode="false" HeaderText="رقم المكينة<br/>Machine ID" />
<asp:BoundField DataField="payment_type" HtmlEncode="false" HeaderText="طريقة الدفع<br/>Payment Type" />
<asp:BoundField DataField="price" HtmlEncode="false" HeaderText="السعر<br/>Price" />
<asp:BoundField DataField="qty" HtmlEncode="false" HeaderText="الكمية<br/>Qty" />
<asp:BoundField DataField="total" HtmlEncode="false" HeaderText="الإجمالي<br/>Total Amount" />
<asp:BoundField DataField="userID" HtmlEncode="false" HeaderText="المستخدم<br/>User" />
<asp:BoundField DataField="vat_amount" HtmlEncode="false" HeaderText="الضريبة<br/>VAT Amount" />
</Columns>
<PagerStyle HorizontalAlign="Center" CssClass="GridPager" />
<HeaderStyle HorizontalAlign="Center" />
</asp:GridView>
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; }
}
private List<Root> GetDataFromJSON()
{
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()));
}
}
}
}
return roots;
}
private void BindData()
{
List<Root> roots = GetDataFromJSON();
if (ddlBranchNumbers.SelectedIndex > 0)
{
roots = roots.Where(x => x.branch_num.EndsWith(ddlBranchNumbers.SelectedValue.Trim())).ToList();
}
if (ddlMachineNumbers.SelectedIndex > 0)
{
roots = roots.Where(x => x.machineID.EndsWith(ddlMachineNumbers.SelectedValue.Trim())).ToList();
}
gvInvoices.DataSource = roots;
gvInvoices.DataBind();
lblTotalRecords.Text = roots.Count.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
System.Web.UI.HtmlControls.HtmlGenericControl li = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Page.Master.FindControl("Main_lnkmnu_Harqat_Fawatir");
li.Attributes.Add("class", "menu single-menu active");
if (!this.IsPostBack)
{
this.BindDropDownList();
this.BindData();
}
}