VB.net动态标签列表

时间:2015-12-26 23:06:13

标签: asp.net vb.net dynamic label

我想创建一个动态Label列表。人们可以插入一个数字及其名称,单击更改Button,如果该数字没有任何其他条目,Label中的文本应更改为名称。当然,所有旧条目都应保留。

所以这是我的尝试:

Default.aspx的



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <br />
        <asp:TextBox ID="txtnumber" runat="server" Width="25px"></asp:TextBox>
        <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
        &nbsp;<asp:Label ID="Label1" runat="server"></asp:Label>
        <br />
        <asp:Button ID="btn2" runat="server" Text="Create" />
        <asp:Button ID="btn3" runat="server" Text="Change" />
        <br />
        <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
    </form>
</body>
</html>
&#13;
&#13;
&#13;

Default.aspx.vb

&#13;
&#13;
Partial Class _Default
    Inherits System.Web.UI.Page

    Private Sub _Default_Load(sender As Object, e As EventArgs) Handles Me.Load

        Dim x As Integer = Application("eCount")

        For i = 1 To x

            Dim xName As String = Application("eName")
            Dim myLabel As Label = New Label()

            If Application("eNummer") = i And Application("blocked" + i.ToString()) = False Then
                myLabel.ID = "MyLabel" + i.ToString()
                myLabel.Text = i.ToString() & " " & xName & "<br>"
                ph.Controls.Add(myLabel)

                Application("blocked" + i.ToString()) = True
                Application("blockname" + i.ToString()) = xName

            ElseIf Application("eNummer") = i And Application("blocked" + i.ToString()) = True Then
                myLabel.ID = "MyLabel" + i.ToString()
                myLabel.Text = i.ToString() & " " & Application("blockname" + i.ToString()) & "<br>"
                ph.Controls.Add(myLabel)
            Else
                myLabel.ID = "MyLabel" + i.ToString()
                myLabel.Text = i.ToString() & " Noch nicht vergeben!" & "<br>"
                ph.Controls.Add(myLabel)
            End If

        Next i
    End Sub

    Protected Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click

        Application("eCount") = txtnumber.Text

        Response.Redirect("Default.aspx")

    End Sub

    Protected Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click

        Application("eNummer") = txtnumber.Text
        Application("eName") = txtname.Text

        Response.Redirect("Default.aspx")

    End Sub
End Class
&#13;
&#13;
&#13;

0 个答案:

没有答案