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