473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Optional display of a control in a GridView cell

58 New Member
Okay, here another problem I'm having difficulty solving...

I've got a cell in my GridView that I need to have a control optionally displayed. Specifically, I have a cell with a bound variable of type Label. In that same cell, I also want to display a button (unbound). I can do that with something like this:

Expand|Select|Wrap|Line Numbers
  1.                    <ItemTemplate> 
  2.                     <asp:Label ID="completed_date" runat="server" Text='<%# Bind("completed_date") %>'></asp:Label><br>
  3.                     <asp:Button ID="MarkAsCompletedButton" runat="server" CommandName="MarkAsCompleted" Text="Mark As Completed" />
  4.                    </ItemTemplate>
  5.  
Works great, but I only want to display the button if the "completed_date" label is blank (which, BTW, is stored as a string, not datetime). How do I do that?

Robert
Apr 22 '08 #1
4 1194
Frinavale
9,735 Recognized Expert Moderator Expert
Okay, here another problem I'm having difficulty solving...

I've got a cell in my GridView that I need to have a control optionally displayed. Specifically, I have a cell with a bound variable of type Label. In that same cell, I also want to display a button (unbound). I can do that with something like this:

Expand|Select|Wrap|Line Numbers
  1.                    <ItemTemplate> 
  2.                     <asp:Label ID="completed_date" runat="server" Text='<%# Bind("completed_date") %>'></asp:Label><br>
  3.                     <asp:Button ID="MarkAsCompletedButton" runat="server" CommandName="MarkAsCompleted" Text="Mark As Completed" />
  4.                    </ItemTemplate>
  5.  


Works great, but I only want to display the button if the "completed_date" label is blank (which, BTW, is stored as a string, not datetime). How do I do that?

Robert
Try the same CSS stuff on your button that you did for hiding your index.
It's a bit trickier though....during your RowDataBound event you have to grab the contents of the cell, cast it to a button and then set the CSS style for the button.

Cheers!
-Frinny
Apr 22 '08 #2
RobertTheProgrammer
58 New Member
Hmm...

I'm still relatively new to ASP.NET and web programming. Do you mind giving a little more detail about how I go about the task of "cast it to a button and then set the CSS style for the button"? The first part I've got. Thanks.

Robert
Apr 22 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Hmm...

I'm still relatively new to ASP.NET and web programming. Do you mind giving a little more detail about how I go about the task of "cast it to a button and then set the CSS style for the button"? The first part I've got. Thanks.

Robert

I'm not sure if you're using C# or VB.NET ...but basically in your RowDataBound event handler method for your GridView you would have something like:

VB.Net code:
Expand|Select|Wrap|Line Numbers
  1.             Dim theButton As Button = CType(e.Row.FindControl("myButton"), Button) ' this finds the control and casts it into a button...
  2.             If Not theButton Is Nothing Then
  3.                  theButton.style.add("display","none")
  4.                 'or set the CSS....like
  5.                 'theButton.CssClass = "noShow"
  6.            End If
  7.  
C# code (please note that my C# syntax may not be 100% working...but here's the general idea)
Expand|Select|Wrap|Line Numbers
  1.             Button theButton = (Button) e.Row.FindControl("myButton"); // this finds the control and casts it into a button...
  2.             If ( theButton != null)
  3.             {     theButton.style.add("display","none");
  4.                 //or set the CSS....like
  5.                //theButton.CssClass = "noShow";
  6.            }
  7.  
-Frinny
Apr 23 '08 #4
RobertTheProgrammer
58 New Member
Ah! I get it now. I just didn't understand the terminology.

Many, many thanks for your assistance.

Robert
Apr 23 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
8549
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row...
6
11105
by: AG | last post by:
I have a gridview with a template column containing an imagebutton to delete the row. Under some condition I don't want the row to be deleted, so would like to remove the button. In the...
7
10362
by: aljamala | last post by:
Hi, I was wondering if there is a way to make a single cell readonly within a GridView? I know you can do it for a column but what about a cell within that column? Thanks!
3
6063
by: sheenaa | last post by:
Hello friends, I m using ASP.NET with C# 2005 and SQL SERVER 2005 for the ASP.Net Website. I m using sqldatasource to connect and retrieve the data from database and then it displays the data...
3
3299
by: Bill Gower | last post by:
I have an cell which contains a field member which is filled with String.Empty. When I retrieve the value in the cell with Cells.Text.ToString() and try to compare it to String.Empty, I can't...
1
4501
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
2
1407
by: LsK_Lele | last post by:
Hi, I have a problem in my C# web project: I have extended the GridView class to add some sorting features. Additionally, I need to add a quick-filter table at the bottom of this control, that...
0
1238
by: teressa | last post by:
Hi, I am new to Grid view Control. I have a page with many icons on it for different purposes. I want to add a Grid View where I want to load data with different columns. Below is my...
1
1731
by: nihaa | last post by:
Hi , i want to add subheadings to a repeater based on the categories. I am able to do this on gridview control but not in arepeater. this is the code used in girdview if (e.Row.RowType...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.