Solved

DataList Label control from .aspx.vb

Posted on 2008-10-30
2
681 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a complete list of ASP.NET page load events 3 29
vbModal 12 38
Extracting last characters in a substring 5 21
Message not shown 5 34
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now