I want to filter Gridview along with nested GridView. I wrote the following code
<%@ Page Title="Print Bill" Language="C#" MasterPageFile="~/Inventory.master" AutoEventWireup="true"
CodeFile="frmSaleReciept.aspx.cs" Inherits="frmSaleReciept" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("[src*=plus]").live("click", function () {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "images/minus.png");
});
$("[src*=minus]").live("click", function () {
$(this).attr("src", "images/plus.png");
$(this).closest("tr").next().remove();
});
</script>
<div class="modal-body">
<div class="form-group">
<div class="row">
<div class="col-sm-3">
<label class="control-label" style="margin-top: 10px;">
Reciept No.</label>
<asp:TextBox ID="txtANote" runat="server" class="form-control" placeholder="Copy Recipet No from below Gridview and Paste here for print"></asp:TextBox>
</div>
<br />
<div class="col-sm-6">
<asp:Button ID="btnCust" Text="Get Data" runat="server" Class="btn btn-success" onclick="btnCust_Click"
/>
<asp:Button ID="btnReci" Text="Print Reciept" runat="server" Class="btn btn-danger"
onclick="btnReci_Click" />
<label class="control-label" style="margin-top: 10px; color: Green;">
Total Paid
</label>
<span class="badge">
<asp:Label ID="lblTotal" runat="server"></asp:Label></span>
</div>
</div>
</div>
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover"
RowStyle-Wrap="false" HeaderStyle-Wrap="false" DataKeyNames="InvoiceNo" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover"
RowStyle-Wrap="false" HeaderStyle-Wrap="false">
<Columns>
<asp:TemplateField HeaderText="Sr. No." ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblRowNumber" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceNo" HeaderText="Invoice No" />
<asp:BoundField ItemStyle-Width="150px" DataField="BrandID" HeaderText="Product Code" />
<asp:BoundField ItemStyle-Width="150px" DataField="BrandName" HeaderText="Product Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Qty" HeaderText="Quantity" />
<asp:BoundField ItemStyle-Width="150px" DataField="Price" HeaderText="Price" />
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceDate" HeaderText="Sale Date" />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceNo" HeaderText="Invoice No." />
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceDate" HeaderText="Sold Date" />
<asp:BoundField ItemStyle-Width="150px" DataField="SubTotal" HeaderText="Sub Total" />
<asp:BoundField ItemStyle-Width="150px" DataField="GrandTotal" HeaderText="Grand Total" />
<asp:BoundField ItemStyle-Width="150px" DataField="TotalPayment" HeaderText="Paid" />
<asp:BoundField ItemStyle-Width="150px" DataField="PaymentDue" HeaderText="Due" />
<asp:BoundField ItemStyle-Width="150px" DataField="CName" HeaderText="Contact Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="CPhone" HeaderText="Phone" />
<asp:BoundField ItemStyle-Width="150px" DataField="Status" HeaderText="Status" />
</Columns>
</asp:GridView>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="false" Class="table table-striped table-bordered table-hover">
</asp:GridView>
</div>
</asp:Content>
protected void btnCust_Click(object sender, EventArgs e)
{
gvCustomers.DataSource = GetData("select * from tblSales where InvoiceNo=@InvNo order by InvoiceNo desc; "); //
gvCustomers.DataBind();
//select * from tblSales where InvoiceDate between '13.02.2019' and '13.02.2019' order by InvoiceNo desc;
}
private static DataTable GetData(string query)
{
string strConnString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString)) {
using (SqlCommand cmd = new SqlCommand())
{
//cmd.Parameters.Add(new SqlParameter("@InvNo", txtANote.Text.Trim()));
cmd.CommandText = query;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@InvNo", txtANote.Text);
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//string Id = gvCustomers.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvOrders = e.Row.FindControl("gvOrders") as GridView;
gvOrders.DataSource = GetData(string.Format("select InvoiceNo,so.InvoiceDate,BrandID,BrandName,so.Qty,so.Price from tblItemSold as so inner join tblBrand as st on so.ItemCode = st.BrandID where InvoiceNo='{0}'", txtANote.Text.Trim()));//{0}
gvOrders.DataBind();
}
}
It is showing error an object reference is required for the non-static field, method, or property on following line.
cmd.Parameters.AddWithValue("@InvNo", txtANote.Text);
how to get solution pls