Solved

DataList Label control from .aspx.vb

Posted on 2008-10-30
2
685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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