Solved

Unable to hide certain rows in datalist

Posted on 2004-08-17
6
490 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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