asp.net c# tutorials and examples code for web developers

Sunday, January 18, 2009

For loop through an int array in asp.net c#

For loop through an int array
IntArrayForLoop.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Label1.Text = "Int array created successfully!";
        Label2.Text = "Array Elements: ";
        int[] myNumbers = {50,100,150,200,250,300};

        for (int i = 0; i < myNumbers.Length;i++ )
        {
            Label2.Text += myNumbers[i].ToString() + " ";
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to get output of an int array using for loop in asp.net</title>
</head> 
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">asp.net array example:<br /> Int Array and For Loop</h2>
        <asp:Label 
             ID="Label1" 
             runat="server" 
             Font-Size="Large"
             ForeColor="Crimson"
             Font-Bold="true"
             Font-Italic="false"
             >
        </asp:Label>
        <br />
        <asp:Label 
             ID="Label2" 
             runat="server" 
             Font-Size="Large"
             ForeColor="DodgerBlue"
             Font-Bold="true"
             Font-Italic="true"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             OnClick="Button1_Click"
             Font-Bold="true"
             Text="Create Int Array and Get Output Using For Loop"
             ForeColor="Crimson"
             />   
    </div>
    </form>
</body>
</html>






Related asp.net examples