Solved

Unable to hide certain rows in datalist

Posted on 2004-08-17
6
492 Views
Last Modified: 2011-08-18
Hello there,

I have a datalist (described below).  When the list is databound I want to hide certain rows based on whether or not the text of one of the fields is a certain value, if it is not 'Available' then I want to hide the row.

Does anyone have an idea as to why this is not working?  

Code listed below:

<asp:DataList ID="lstStock" Runat="server" DataKeyField="ID" cellspacing="0" cellpadding="3" rules="all" bordercolor="#FF6600" border="2" style="border-color:#FF6600;border-width:2px;border-style:solid;border-collapse:collapse;">
      <HeaderTemplate>      
            <span class="fieldtitle">Barcode</span></td>
            <td><span class="fieldtitle">Loan type</span></td>
            <td><span class="fieldtitle">Location</span></td>
            <td><span class="fieldtitle">Availability</span>
      </HeaderTemplate>
      <ItemTemplate>
            <%#Container.DataItem("BarCodeID") %></td>
            <td><%#Container.DataItem("LoanType") %></td>
            <td><%#Container.DataItem("Location") %></td>
            <td><asp:Label ID="lblAvailability" Runat="server"></asp:Label>
      </ItemTemplate>
</asp:DataList>
And the databound routine:

Private Sub lstStock_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles lstStock.ItemDataBound
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                Dim tmpLbl As Label = CType(e.Item.FindControl("lblAvailability"), Label)

                ' Set up stock object from data key field
                Dim objStock As New ICCatalogue.BusObjects.Stock(False, Convert.ToInt32(lstStock.DataKeys(e.Item.ItemIndex)))

                'Get the stock item availability
                tmpLbl.Text = objStock.LoanStatus

                ' See if stock item availablity is 'Available', if not then hide the row.
                If Not tmpLbl.Text = "Available" Then
                    e.Item.Visible = False
                End If

                ' Tidy up
                objStock.Disconnect()
                objStock.Dispose()
                objStock = Nothing
            End If
        End Sub
0
Comment
Question by:a877059
6 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11819773
Why don't you filter the dataview, based on your criteria, before binding the table to the List ?
Take a look here...
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataDataViewClassRowFilterTopic.asp
-Baan
0
 

Author Comment

by:a877059
ID: 11819810
The way the system was devised, the availability of the item isn't actually part of the dataset, it is determined afterwards, so I cannot filter on it.
0
 
LVL 20

Expert Comment

by:ihenry
ID: 11827794
Have you tried this?

If Not tmpLbl.Text = "Available" Then
   lstStock.Items[e.Item.ItemIndex].Visible = false;
End If

0
 

Author Comment

by:a877059
ID: 11828735
Yeah - it still dosn't pick up the fact that the row should be invisible.

I have converted the datalist to a datagrid and it works fine.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 12142841
Submitted to PAQ with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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