Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I need to hide my edit button if one of the date column in gridview is less than the current date .However it is hiding the edit button in all columns .Any help will be really appreciated .Thanks in advance .

What I have tried:

 if (e.Row.RowType == DataControlRowType.DataRow)
            {
DateTime myDate = (DateTime)DataBinder.Eval(e.Row.DataItem, "appoinmentDate");
                string apintdate=DataBinder.Eval(e.Row.DataItem, "appoinmentDate").ToString();
                if (DateTime.Now <= myDate)
                {
                    Button btnEdit = (Button)e.Row.FindControl("ibut_Edit");
                    btnEdit.Visible = false;
                }
}
Posted
Updated 22-May-18 8:07am
Comments
David O'Neil 22-May-18 9:37am    
Are all the buttons in the row called 'ibut_Edit'?
Member 12926744 22-May-18 9:41am    
No...they all are in the same column
Richard Deeming 22-May-18 10:02am    
"... if one of the date column in gridview is less than the current date ..."
"if (DateTime.Now <= myDate) { ... }"

So which is it? Your question says you want to hide the button if the date column is less than the current date. But your code is hiding the button if the date column is greater than or equal to the current date.
Member 12926744 22-May-18 10:13am    
Sorry that was my mistake...actually date column should be less than the current date.Even if I changed to less than, still it is not working .It is hiding all the buttons in all rows.
Vincent Maverick Durano 23-May-18 0:30am    
Have you tried setting a break point into your code and check if all dates you compared is really less than the current date?

1 solution

Hi there,

Take a look at this link; I have come to trust the CompareTo method.

Moreover, consider removing/deleting undesired buttons instead of just making them invisible.

By the way, the line:
string apintdate=DataBinder.Eval(e.Row.DataItem, "appoinmentDate").ToString();
does not seem to play a part in that code. If it is used afterwards, then ignore this note.

Cheers!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900