Solved

Conditional Visibility in DataGrid

Posted on 2009-04-15
4
930 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now