?
Solved

Unable to hide certain rows in datalist

Posted on 2004-08-17
6
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

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 …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

741 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