Reputation: 55
I'm using C# and I get data from database like this:
da.SelectCommand = new SqlCommand("SELECT name,company,startdate,enddate,DATEDIFF(day,GETDATE(),enddate) AS days FROM Person", cn);
ds.Clear();
da.Fill(ds);
dgvViolation.DataSource = ds.Tables[0];
and the data will dispaly in datagridview like this :
name company startdate enddate days
---------------------------------------
john IBM 12/2/2012 20/2/2012 5
steven IBM 1/2/2012 12/2/2012 -3
I need the datagridview to display the positive values that appear in the days columns only. How do I do this?
Upvotes: 0
Views: 177
Reputation: 246
Why don't you just change your SQL command to return the values above 0?
But if you want to do it with all the data returned, you can use the RowDataBound event of the gridview, something like this:
protected void gridview_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
{
//look at the value of the days column and use e.Row.Style["Display"] = "none"; to hide it.
}
}
Upvotes: 0
Reputation: 16043
Change the query to
"SELECT name,company,startdate,enddate,DATEDIFF(day,GETDATE(),enddate) AS days FROM Person WHERE days > 0"
Upvotes: 1