Hello-- I have an ordering screen that displays hundreds of items in a datagrid and provides a blank for the user to enter a Quantity. Datagrid "CatalogGrid" is bound to a datasource which is based on the System.Collection.CollectionBase class. If the user has entered a Quantity on a row, the quantity is displayed on the same datagrid row via a datasource which is based on the System.Collections.DictionaryBase class. (See code snippets below.)

My goal is to create a new Order Preview page that shows only ordered items, allowing the user to change the quantity or delete. In that situation, ss there a way to hide rows where the Quantity is blank, while still using this datasource implementation? See mock-up image here: http://www.enardoni.com/download/orderpreview_mockup.gif

Thank you in advance for your consideration!

===
ASP.NET with Visual Basic, using Visual Studio 2003. I'm a relatively new developer who inherited the source code from an expert programmer, so please bear with me!

From the ASPX page:

<asp:BoundColumn DataField="ItemNumber" HeaderText="Item #">
    <HeaderStyle Width="3%"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Qty">
    <HeaderStyle Width="5%"></HeaderStyle>
    <ItemTemplate>
        <asp:TextBox id="QuantityTextbox" runat="server" [B]Text='<%# DataGrid_BindQuantity(DataBinder.Eval(Container, "DataItem.ItemId")) %>'[/B]  </asp:TextBox>
    </ItemTemplate>
</asp:TemplateColumn>

From the code-behind:

CatalogGrid.DataSource = CatalogItems.PageFill
    CatalogGrid.DataBind()
Protected Function DataGrid_BindQuantity(ByVal dataItem As Object) As String
            Dim value As String = String.Empty

            Dim ThisOrder As MyOrderClass = CType(Me.GetSessionValue("Order"), MyOrderClass)
            If Not IsNothing(ThisOrder) Then
                Dim ItemId As String = dataItem.ToString
                If ThisOrder.OrderedItems.Contains(ItemId) Then
                    value = ThisOrder.OrderedItems(ItemId).Quantity.ToString()
                End If
            End If

            Return value
        End Function

Recommended Answers

All 3 Replies

Try

If datagrid.rows.count = 0 then
datagrid.visible = False
else
datagrid.visible = True
End If

Thank you for writing, Peter. Your suggested code appears to hide the entire datagrid; in this case, I just need to hide the rows of the datagrid that do not have a Quantity entered.

What do you think?

I would normally use this with a dataview in Windows Applications but the concept should be the same

Dim SQLRow as datarow
Dim Index as Integer = 0

For Each SQLRow In DataGrid.Rows
If SQLRow(ColumnName).tostring = "" Then
DataGrid.Rows(Index).Visible = False
else
DataGrid.Rows(Index).Visible = True
End If

Index += 1
Next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.