Solved

Unable to hide certain rows in datalist

Posted on 2004-08-17
6
488 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
Comment Utility
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
Comment Utility
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
Comment Utility
Have you tried this?

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

0
 

Author Comment

by:a877059
Comment Utility
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
Comment Utility
Submitted to PAQ with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now