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
Solved

Conditional Visibility in DataGrid

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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