Solved

DataList Label control from .aspx.vb

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 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…

759 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

20 Experts available now in Live!

Get 1:1 Help Now