?
Solved

DataList Label control from .aspx.vb

Posted on 2008-10-30
2
Medium Priority
?
686 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 200 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] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

766 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