Solved

Unable to hide certain rows in datalist

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

732 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