Solved

Conditional Visibility in DataGrid

Posted on 2009-04-15
4
936 Views
Last Modified: 2012-05-06
My query pulls in multiple fields into a DataGrid.  I am trying to hide one field in the grid if another field has nothing in it.

This post would appear to provide my solution:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23564496.html?sfQueryTermInfo=1+10+bind+condit

But when I try it I get an error:
<asp:TextBox ID="Actual_Task_Start_Date" runat="server" AutoPostBack="true" Font-Size="8pt"
    Style="text-align: center; width: 60px;" Text='<%# Bind("Actual_Task_Start_Date","{0:d}") %>'
    Visible='<%= (Request.QueryString("Planned_Task_Start_Date") Is Nothing) %>'
    Width="60px"></asp:TextBox>

The error is:
Generation of designer file failed: Cannot create an object of type 'System.Boolean' from its string representation '<%= (Request.QueryString("Planned_Task_Start_Date") Is Nothing) %>' for the 'Visible' property.

What should I be doing differently?
0
Comment
Question by:wsturdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 8

Expert Comment

by:bedanand
ID: 24149458
HI

<asp:TextBox ID="Actual_Task_Start_Date" runat="server" AutoPostBack="true" Font-Size="8pt"
    Style="text-align: center; width: 60px;" Text='<%# Bind("Actual_Task_Start_Date","{0:d}") %>'
    Visible='<%= (Request.QueryString("Planned_Task_Start_Date") Is Nothing) %>'
    Width="60px"></asp:TextBox>
As you mentioned you if there is nothing on the another field (i suppose its database field).
So the code shoule be like this


<asp:TextBox ID="Actual_Task_Start_Date" runat="server" AutoPostBack="true" Font-Size="8pt"
    Style="text-align: center; width: 60px;" Text='<%# Bind("Actual_Task_Start_Date","{0:d}") %>'
    Visible='<%# (Eval("Planned_Task_Start_Date") Is Nothing) %>'
    Width="60px"></asp:TextBox>

Open in new window

0
 
LVL 1

Author Comment

by:wsturdev
ID: 24149909
Okay.  Unfortunately, even though the first row of the DataGrid has a Planned_Task_Start_Date, the last does not, so the final result is the field Actual_Task_Start_Date is hidden for every row.
How can I do this on a row by row basis?
0
 
LVL 1

Author Comment

by:wsturdev
ID: 24150191
If it is not possible to change the visibility of a textbox on a row by row basis in a DataGrid...
The text box I am trying to hide/show is the second part of a 2-part construct:
<asp:Label ID="Planned_Task_Start_Date" runat="server" Text='<%# Bind("Planned_Task_Start_Date","{0:d}")%>'
Width="60px"></asp:Label>
<asp:TextBox ID="Actual_Task_Start_Date" runat="server" AutoPostBack="true" Font-Size="8pt"
Style="text-align: center; width: 60px;" Text='<%# Bind("Actual_Task_Start_Date","{0:d}") %>'
Visible='<%# Not(Eval("Planned_Task_Start_Date") Is Nothing) %>' Width="60px"></asp:TextBox>
I want to either:
1. Only show the text box "Actual_Task_Start_Date" when the label "Planned_Task_Start_Date" has a valid date in it.  I was trying to use Visible='<%# Not(Eval("Planned_Task_Start_Date") Is Nothing) %>'  to accomplish this.
2. Always show the text box "Actual_Task_Start_Date" even when the label "Planned_Task_Start_Date" does NOT have a valid date in it, but there needs to be a blank line above "Actual_Task_Start_Date" (representing the space in which a Planned_Task_Start_Date would be if it were present.  If Planned_Task_Start_Date has Null in it, the space for the label compresses up to nothing and the Actual_Task_Start_Date moves up to the top of the row. To counteract this, how would I modify Text='<%# Bind("Planned_Task_Start_Date","{0:d}")%>' to either show the date or show a "blank line" if there was no date.?
0
 
LVL 1

Accepted Solution

by:
wsturdev earned 0 total points
ID: 24204100
To do this on an individual row basis, I put code into the Page PreRender to hide the field if it was empty.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question