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,
re: How do I exclude hyperlink fields when hiding detailsview empty rows?
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.
re: How do I exclude hyperlink fields when hiding detailsview empty rows?
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(" ", "").Trim();
if (data == null || data == "")
{
r.Visible = false;
}
}
}
OUTPUT
re: How do I exclude hyperlink fields when hiding detailsview empty rows?
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,
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 Installer (.MSI) installation packages that is 100% integrated into the Visual Studio.NET IDE. . It is a complete and user-friendly
Visual Studio.NET: Help Yourself! Visual Studio.NET: Help Yourself! By Peter A. Bromberg, Ph.D. Peter Bromberg I'm constantly annoyed by the number of developers using Visual Studio.NET who don't seem to see the need to create cryptic kind that only the original developer would understand! With Visual Studio.NET there is no excuse for this kind of
Migrating to Visual Studio.NET 2003: A Developer Perspective Migrating to Visual Studio.Net 2003: A Developer - oriented analysis By Peter A. Bromberg, Ph Platform On April 24, 2003 Microsoft Windows Server 2003 and Visual Studio .NET 2003 are officially released. Many developers and beta testers (myself through the present from these efforts was SOAP, Webservices, the .NET platform and the C# and VB.NET languages, XML support
Need Visual Studio .NET 2005 tutorials sites Hi, Can some one send some sites to learn Visual Studio .NET 2005.Need some tutorials. . Thanx in advance Visual Studio 2005 Hands-On Tutorial http: / / www.15seconds.com / issue / 060427 htm Introduction to Visual Studio .net http: / / www.exforsys.com / content / view / 1599 / 354 / Check
Visual Studio .NET 2008 - Speed Up XAML Load Times Do your XAML files load up in Visual Studio .NET 2008 as slow as mine? Here is a workaround that might help. Visual Studio .NET 2008 is an extreme disappointment for me. Its performance is XAML editor. What infuriates me is that people on the Visual Studio .NET development team put this app through the testing
Revisited: Guerilla Install Visual Studio.NET Still having trouble installing the released version of Visual Studio.NET over the BETA? Read the following web page AND THEN addendum which follows in this post. Guerilla Install Tactics for Visual Studio.NET Final By Peter A. Bromberg, Ph.D. http: / / www.eggheadcafe your machine. I also managed to get my Beta VS.NET 'partially uninstalled' - - in my case it was purposeful since the
Visual studio.Net problem with C# project Hi , To ask my question I have to write this long story. First I had installed Visual studio.Net framework with .Net framework beta 1.0 from 4Cds package. When I install this product it shows that it is installing Visual studio 7.0 professional version. Now when I found new version of .Net framework 1.1 beta is available I uninstalled the whole
Build a Quick Visual Studio.NET Search Macro Build a Quick Visual Studio.NET Google Search Macro By Peter A. Bromberg, Ph.D. Peter Bromberg The builders of Visual Studio.NET put a lot of time and thought into making a get productivity gains. Do you ever find yourself working in Visual Studio and firing up your browser to do a Google