Question Manipulating gridview data - converting information

kizzelwhix

New member
Joined
Feb 20, 2013
Messages
2
Programming Experience
5-10
Hello, I'm relatively new to ASP.NET - however I've been working with 'Classic' ASP for over 10 years now.

Its taking me a bit to get through the learning curve of the new object oriented style versus the linear method I'm used to.

Anyway, Basically what I want to do is determine if there is a positive quantity in inventory, to simply say "In Stock" versus posting the actual quantity. Sub posted below & according web form.

The hurdle Im facing, is that it doesnt seem to do anything. at all. Im very frustrated right now, and while I've found topics somewhat similar, I have not found one yet that addresses this directly. Hopefully there is some expert out there that sees what I'm trying to do and can help.
(I have a feeling the stuff I've highlighted in red is the culprit, however Im at a loss for retrieving and processing the information the way I want to, other than this)
Thank you for your time.
VB.NET:
    Sub evalInventory(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
        If (e.Item.ItemType = ListViewItemType.DataItem) And (e.item.findcontrol("QTY Available") IsNot (Nothing)) Then
            'Format this the way I want, I hope
           [COLOR=#b22222] Dim QTYLabelInt As Integer = CInt(CType(e.Item.FindControl("QTY Available"), Literal).toString())[/COLOR]
            Dim QTYLabel As Label = CType(e.item.findcontrol("QTY Available"), Label)
            
            If QTYLabelInt > 0 Then
                QTYLabel.Text = "In Stock"
                QTYLabel.Font.Bold = True
            Else
                QTYLabel.Text = "Out of Stock"
                QTYLabel.Font.Italic = True
            End If
        End If
    End Sub
****
*******-----Edit------*****

I've also tried this:
VB.NET:
        If (e.Item.ItemType = ListViewItemType.DataItem) And (e.item.findcontrol("QTY Available") IsNot (Nothing)) Then
            'Format this the way I want, I hope
            [COLOR=#b22222]Dim qtyLabelIntRow As Data.DataRowView = CType(e.item.dataitem, System.Data.DataRowView)
            Dim QTYLabelInt As String = qtyLabelIntRow("QTY Available").ToString()[/COLOR]
            
            'Dim QTYLabelInt As Integer = CInt(CType(e.Item.FindControl("QTY Available"), Literal).toString())
            Dim QTYLabel As Label = CType(e.item.findcontrol("QTY Available"), Label)
            
            If CInt(QTYLabelInt) > 0 Then
                QTYLabel.Text = "In Stock"
                QTYLabel.Font.Bold = True
            Else
                QTYLabel.Text = "Out of Stock"
                QTYLabel.Font.Italic = True
            End If
        End If


VB.NET:
       <asp:ListView ID="InventoryView" DataSourceID="RMW" ConvertEmptyStringToNull="true"
        OnItemDataBound="evalInventory" runat="server">
        <layouttemplate>
          <table cellpadding="2" width="680px" border="0">
            <tr id="Tr1" style="background-color: #ADD8E6" runat="server">
                <th id="Th1" runat="server">Item Number</th>
                <th id="Th2" runat="server">Item Name</th>
                <th id="Th3" runat="server">Stock Status</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="InventoryPager" PageSize="50">
            <Fields>
              <asp:NumericPagerField ButtonCount="10" /> 
            </Fields>
          </asp:DataPager>
        </layouttemplate>
        <itemtemplate>
          <tr id="Tr2" style="background-color: #CAEEFF" runat="server">
            <td>
              <asp:Label ID="ItemNumberLabel" runat="server" Text='<%#Eval("Item Number")%>' />
            </td>
            <td>
              <asp:Label ID="ItemNameLabel" runat="server" Text='<%#Eval("Item Description")%>' />
            </td>
            <td>
              <asp:Label ID="QTYLabel" runat="server" Text='<%#Eval("QTY Available")%>' />
            </td>
          </tr>
        </itemtemplate>
    </asp:ListView>
 
Last edited:
Got it. I was way off

VB.NET:
    Sub evalInventory(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
        If (e.Item.ItemType = ListViewItemType.DataItem) Then
            'Format this the way I want, I hope
            Dim rowView As Data.DataRowView = CType(e.item.dataitem, System.Data.DataRowView)
            Dim QTYLabelInt As Integer = CInt(rowView("QTY Available").ToString())


            Dim qtyText As String
            Dim qtyFMT As String
            If CInt(QTYLabelInt) > 0 Then
                qtyText = "In Stock"
                qtyFMT = True
            Else
                qtyText = "Out of Stock"
                qtyFMT = False
            End If
            
            Dim QTYLabel As Label = CType(e.item.findcontrol("QTYLabel"), Label)
            QTYLabel.Text = qtyText
            QTYLabel.Font.Bold = qtyFMT
        End If
    End Sub
 
Back
Top