Solved

Conditional Visibility in DataGrid

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
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.

914 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

21 Experts available now in Live!

Get 1:1 Help Now