Solved

DataList Label control from .aspx.vb

Posted on 2008-10-30
2
683 Views
Last Modified: 2012-05-05
Hi experts,

In Datalist, I assigned Label named "lblWarning" with Visible = "False". When entered quantity is over than available quantity, I want to change Visible = "True" in .aspx.vb code.
How can I do it?

Followings are my codes.

========== 1. DEFAULT.ASPX CODE ===========
     <asp:DataList ID="DataList1" runat="server" RepeatColumns="3" Width="99%" RepeatDirection="Horizontal">
        <ItemTemplate>
          <table style="width: 99%;" cellpadding="4">
           <tr>
             <td>    
                <asp:Literal ID="litID" runat="server" Text='<%# Eval("ID") %>' Visible="false"/>          
                Available:<asp:Literal ID="LitAvailable" runat="server" Text='<%# String.Format("{0:g}", Eval("Available")) %>' />
            </td>
            <td>              
                <asp:TextBox ID="txtQuantity" runat="server" Width="30px" OnTextChanged="txtQuantity_TextChanged" ></asp:TextBox>
                <asp:Label ID="lblWarning" runat="server" Text="*" ForeColor="Red" Visible="False"></asp:Label>
            </td>
           </tr>
          </table>
        </ItemTemplate>
        <ItemStyle VerticalAlign="Top" />
      </asp:DataList>

.========== 2. DEFAULT.ASPX.VB CODE ===========
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim Quantities(pubVars.dliRowCount, 2) As Integer
.
.
.
    Protected Sub txtQuantity_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) 'Handles txtQuantity.TextChanged
        Dim ddl As TextBox = DirectCast(sender, TextBox)
        Dim dli As DataListItem = DirectCast(ddl.NamingContainer, DataListItem)
        Dim lbl As Literal = DirectCast(dli.FindControl("LitID"), Literal)      'ProductID
        Dim _productId As Integer = Convert.ToInt32(lbl.Text)
        lbl = DirectCast(dli.FindControl("LitAvailable"), Literal)              'Available Inventory
        Dim _available As Integer = Convert.ToInt32(lbl.Text)
        Dim ix As Integer = dli.ItemIndex
        Dim iy As Integer = ddl.Text            'Order Quantity Entered
        If iy > _available Then                 'If Quantity > Avaialbe,
            iy = _available                     'then Quantity := Available
            lblWarning.Text.Visible = "True" ========================> I want to show * mark when quantity is over than available  ========> How can I do this?
        End If
        Quantities(ix, 0) = ix                  'Index
        Quantities(ix, 1) = iy                  'Quantity
        Quantities(ix, 2) = _productId          'Product
    End Sub
0
Comment
Question by:Takeoutdinner
2 Comments
 
LVL 7

Accepted Solution

by:
the_bachelor earned 50 total points
ID: 22845575
you're almost there
Check the code below out
Protected  Sub txtQuantity_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddl As TextBox = DirectCast(sender, TextBox)
        Dim dli As DataListItem = DirectCast(ddl.NamingContainer, DataListItem)
        Dim lbl As Literal = DirectCast(dli.FindControl("LitID"), Literal)      'ProductID
        Dim _productId As Integer = Convert.ToInt32(lbl.Text)
        lbl = DirectCast(dli.FindControl("LitAvailable"), Literal)              'Available Inventory
 
        Dim warningLabel As Label = DirectCast(dli.FindControl("lblWarning"), Label)
        Dim _available As Integer = Convert.ToInt32(lbl.Text)
        Dim ix As Integer = dli.ItemIndex
        Dim iy As Integer = ddl.Text            'Order Quantity Entered
        If iy > _available Then                 'If Quantity > Avaialbe, 
            iy = _available                     'then Quantity := Available
            warningLabel.Visible = True '========================> I want to show * mark when quantity is over than available  ========> How can I do this?
        End If
        Quantities(ix, 0) = ix                  'Index
        Quantities(ix, 1) = iy                  'Quantity
        Quantities(ix, 2) = _productId          'Product
    End Sub

Open in new window

0
 

Author Closing Comment

by:Takeoutdinner
ID: 31511800
Thanks a lot for your advice.
Have a wonderful week!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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