Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

hiding columns in gird based on column values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
news.microsoft.com - 25 Oct 2007 01:12 GMT
I have a grid that has icons for 2 buttons edit and delete on each row.  I
would like to make the buttons invisible if the dateoccured in the record in
the row is older than this week.  How do I do that?

Bill
IfThenElse - 25 Oct 2007 01:19 GMT
In the databind event handler of your datagrid check for the dateoccured on
each row and hide the button(s).

>I have a grid that has icons for 2 buttons edit and delete on each row.  I
> would like to make the buttons invisible if the dateoccured in the record
> in
> the row is older than this week.  How do I do that?
>
> Bill
Mark Rae [MVP] - 25 Oct 2007 10:49 GMT
>I have a grid that has icons for 2 buttons edit and delete on each row.  I
> would like to make the buttons invisible if the dateoccured in the record
> in
> the row is older than this week.  How do I do that?

<asp:GridView ID="MyGrid" runat="server"
OnRowDataBound="MyGrid_RowDataBound" ........ />

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
       if (Convert.ToDateTime(e.Row.Cells[0].Text) <
DateTime.Now.AddDays(-7))
       {
           e.Row.Cells[2].FindControl("MyEditButton").Visible = false;
           e.Row.Cells[2].FindControl("MyDeleteButton").Visible = false;
       }
   }
}

Obviously, change the column indexes as necessary.

N.B. setting a column's control(s) Visible property to false isn't the same
as hiding the column, which was the title of your OP...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.