Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Conditional Visibility in DataGrid

Posted on 2009-04-15
4
Medium Priority
?
938 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

Industry Leaders: 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

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

597 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