Hiding item in DataGrid

D

David C

I have a DataGrid that displays 3 columns from a list of Files in a
Directory. The first column is a HyperLink that displays the file name with
a link to another page and querystring. Below is the DataGrid and below
that is the ItemDataBound code that is not hiding the file named
"Thumbs.db". What am I doing wrong to hide that cell? p.s. I would prefer to
hide the whole row. Thanks.

David

<asp:DataGrid runat="server" id="articleList"
AutoGenerateColumns="False"
HeaderStyle-BackColor="Navy"
HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt"
HeaderStyle-Font-Bold="True"
DataKeyField="FullName" BackColor="White"
BorderColor="#999999"
BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="File Name"
DataNavigateUrlFormatString="ShowDocs.aspx?doc={0}"
Target="_blank" />
<asp:BoundColumn DataField="LastWriteTime"
HeaderText="Last Updated"
DataFormatString="{0:d}" >
</asp:BoundColumn>
<asp:BoundColumn DataField="Length"
HeaderText="File Size"
DataFormatString="{0:#,### bytes}" >
</asp:BoundColumn>
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black"
/>
<SelectedItemStyle BackColor="#008A8C"
Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" Mode="NumericPages" />
<AlternatingItemStyle BackColor="#DCDCDC" />
<ItemStyle BackColor="#EEEEEE" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True"
Font-Size="15pt" ForeColor="White" />
</asp:DataGrid>

Protected Sub articleList_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
articleList.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim hlcol As HyperLinkColumn = articleList.Columns(0)
Dim value As String

value = hlcol.DataNavigateUrlFormatString.ToString()
If value = "ShowDocs.aspx?doc=Thumbs.db" Then
e.Item.Cells(0).Visible = False
End If
End If
End Sub
 
G

Guest

I have a DataGrid that displays 3 columns from a list of Files in a
Directory.  The first column is a HyperLink that displays the file name with
a link to another page and querystring.  Below is the DataGrid and below
that is the ItemDataBound code that is not hiding the file named
"Thumbs.db". What am I doing wrong to hide that cell? p.s. I would prefer to
hide the whole row.  Thanks.

David

                    <asp:DataGrid runat="server" id="articleList"
                          AutoGenerateColumns="False"
                          HeaderStyle-BackColor="Navy"
HeaderStyle-ForeColor="White"
                          HeaderStyle-Font-Size="15pt"
HeaderStyle-Font-Bold="True"
                          DataKeyField="FullName" BackColor="White"
BorderColor="#999999"
                          BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical">
                        <Columns>
                          <asp:HyperLinkColumn DataNavigateUrlField="Name"
                               DataTextField="Name" HeaderText="File Name"
                               DataNavigateUrlFormatString="ShowDocs.aspx?doc={0}"
Target="_blank" />
                          <asp:BoundColumn DataField="LastWriteTime"
                                  HeaderText="Last Updated"
                                  DataFormatString="{0:d}" >
                          </asp:BoundColumn>
                          <asp:BoundColumn DataField="Length"
HeaderText="File Size"
                              DataFormatString="{0:#,### bytes}" >
                          </asp:BoundColumn>
                        </Columns>
                        <FooterStyle BackColor="#CCCCCC" ForeColor="Black"
/>
                        <SelectedItemStyle BackColor="#008A8C"
Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" Mode="NumericPages" />
                        <AlternatingItemStyle BackColor="#DCDCDC" />
                        <ItemStyle BackColor="#EEEEEE" ForeColor="Black" />
                        <HeaderStyle BackColor="#000084" Font-Bold="True"
Font-Size="15pt" ForeColor="White" />
                     </asp:DataGrid>

    Protected Sub articleList_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
articleList.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
            Dim hlcol As HyperLinkColumn = articleList.Columns(0)
            Dim value As String

            value = hlcol.DataNavigateUrlFormatString.ToString()
            If value = "ShowDocs.aspx?doc=Thumbs.db" Then
                e.Item.Cells(0).Visible = False
            End If
        End If
    End Sub

are you sure that this is correct?
If value = "ShowDocs.aspx?doc=Thumbs.db" Then

To hide the whole row you need to set

for (int i = 0; i < e.Item.Cells.Count; i++)
e.Item.Cells.Visible = true;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top