Data View row filter using data table
I have the following code which doesn't seem to work. In the Button_Click event I populate the datatble and display the results in a grid view.
SqlCommand cmd = new SqlCommand("Select inv_No,inv_Date,Project from Invoice_Master", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dtserch = new DataTable();
adp.Fill(dtserch);
DataView dv = dtserch.DefaultView;
//Inv_No filter
dv.RowFilter = "inv_No='" + CmbSSalesInvNo.Text + "'";
//Date Filter
//convert date format as server date format
if (txtFromDate != "" && txtToDate.Text != "")
{
fromdate = Convert.ToDateTime(txtFromDate .Text).ToString("MM-dd-yyyy");
Todate = Convert.ToDateTime(txtToDate.Text).ToString("MM-dd-yyyy");
}
dv.RowFilter = "ServiceInvoiceDate >= #" + fromdate + "# and ServiceInvoiceDate <= #" + Todate + "#";
//Filter data bind to gridview
DgvAllSalesInvoices.DataSource = dv;
I have the following code which doesn't seem to work. In the Button_Click event I populate the datatble and display the results in a grid view.
SqlCommand cmd = new SqlCommand("Select inv_No,inv_Date,Project from Invoice_Master", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dtserch = new DataTable();
adp.Fill(dtserch);
DataView dv = dtserch.DefaultView;
//Inv_No filter
dv.RowFilter = "inv_No='" + CmbSSalesInvNo.Text + "'";
//Date Filter
//convert date format as server date format
if (txtFromDate != "" && txtToDate.Text != "")
{
fromdate = Convert.ToDateTime(txtFromDate .Text).ToString("MM-dd-yyyy");
Todate = Convert.ToDateTime(txtToDate.Text).ToString("MM-dd-yyyy");
}
dv.RowFilter = "ServiceInvoiceDate >= #" + fromdate + "# and ServiceInvoiceDate <= #" + Todate + "#";
//Filter data bind to gridview
DgvAllSalesInvoices.DataSource = dv;
No comments:
Post a Comment