Visual Studio .NET - How do I exclude hyperlink fields when hiding detailsview empty rows?

Asked By dan
06-Sep-10 02:20 PM
Hello,

I have the following in pageload of detailsview to hide empty fields from displaying.  The problem is it hides hyperlink fields I have as well.  How do I overcome this?  The hyperlink fields are urlstrings page.aspx?id={0}.
 
 protected void dvPersonal_Load(object sender, EventArgs e)
    {
      String data;
      
      foreach (DetailsViewRow r in dvPersonal.Rows)
      {
        if (r.Cells.Count > 1)
        {
          data = r.Cells[1].Text;
        }
        else
        {
          data = r.Cells[0].Text;
        }

        data = data.Replace(" ", "").Trim();
        if (data == null || data == "")
        {
          r.Visible = false;
        }
      }
    }

Thanks,
  Peter Bromberg replied to dan
06-Sep-10 05:58 PM
If it is hiding fields that are null, then your logic is wrong.
Put a breakpoint on each of these lines:

  data = r.Cells[1].Text;

and

  data = r.Cells[1].Text;

and inspect what you see for the value of .Text.
  dan replied to Peter Bromberg
06-Sep-10 11:40 PM
Hello,

an you help me correct the logic?  It works when applied to detailsview onload event, except my hyperlinks do not appear.  I do however want to eliminate future problems I might have and could really use your help. 

In your reply you asked what data was.  For the hyperlink field. it was ""  The other null value are excluded correctly, see OUTPUT.

Thank you,


DETAILSVIEW
    <asp:DetailsView ID="dvPersonal" runat="server" AutoGenerateRows="False" 
    DataKeyNames="id" onload="dvPersonal_Load" DataSourceID="SqlDataSource1" 
    Height="50px" Width="259px" AllowPaging="True" CellPadding="4" 
    ForeColor="#333333" GridLines="None"  
    onpageindexchanging="dvPersonal_PageIndexChanging">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
    <EditRowStyle BackColor="#999999" />
    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
    <Fields>
      <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
        ReadOnly="True" SortExpression="id" />
      <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
      <asp:HyperLinkField DataNavigateUrlFields="id" 
        DataNavigateUrlFormatString="default.aspx?id={0}" HeaderText="New" 
        Text="Link" />
      <asp:BoundField DataField="company" HeaderText="company" 
        SortExpression="company" />
    </Fields>
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  </asp:DetailsView>
DATA
id   name   company
1             CostCo   

CODE
Snippet
  protected void dvPersonal_Load(object sender, EventArgs e)
  {
    String data;

    foreach (DetailsViewRow r in dvPersonal.Rows)
    {
      if (r.Cells.Count > 1)
      {
        data = r.Cells[1].Text;
      }
      else
      {
        data = r.Cells[0].Text;
      }

      data = data.Replace("&nbsp;""").Trim();
      if (data == null || data == "")
      {
        r.Visible = false;
      }
    }
  }

OUTPUT
id 1
company CostCo

  dan replied to dan
07-Sep-10 03:35 AM
Hello,

A workaround solution is to make visible the hyperlink row after it was hidden. 

Snippet
     dvPersonal.Rows[2].Visible = true;
Thanks,
Create New Account
help
Visual Studio .net .NET Framework Hi NG, ich habe vor längerer Zeit mit Visual Studio .Net 2003 gearbeitet und überlege momentan auf einen neueren Stand upzudaten. Ein Visual Studio .Net 2008 scheint es nicht zu geben. Habe zumindest mit googeln nichts gefunden. Was
Wise for Visual Studio.NET Wise for Visual Studio.NET By Peter A. Bromberg, Ph.D. To "Print This Page" Link Peter Bromberg Wise for Visual Studio .NET is a total and complete installation development system for creating and editing Windows® Installer
Visual Studio versioning . . . . how to tell? .NET Framework To my knowledge, Visual studio 6 was released in 1998, then Visual Studio .NET 2002 is VS 7, then Visual Studio .NET 2003 is VS 7.1, then Visual
visual studio.net 2003 and Access 2007 database .NET Framework Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great success. Now
Is Visual Studio self-hosting ? .NET Framework Does Microsoft use Visual Studio IDE, Visual Studio Debugger, Visual Studio Linker and Visual Studio compiler for developing Visual Studio ? Or is Visual Studio not