Use Two dimensional array (C#) : Array « Collections « ASP.Net






Use Two dimensional array (C#)

<%@ Page Language="C#" Debug="true" %>
<script runat="server">

    void Page_Load()
    {
        if(Page.IsPostBack)
        {
            string [,] strClient = new string[4,3]; // 4 people, 3 attributes each
        
            strClient[0,0] = "First Name 1";
            strClient[0,1] = "Last Name 1";
            strClient[0,2] = "111-111-1111";
            strClient[1,0] = "First Name 2";
            strClient[1,1] = "Last Name 2";
            strClient[1,2] = "222-222-2222";
            strClient[2,0] = "First Name 3";
            strClient[2,1] = "Last Name 3";
            strClient[2,2] = "333-333-3333";
            strClient[3,0] = "First Name 4";
            strClient[3,1] = "Last Name 4";
            strClient[3,2] = "444-444-4444";
        
            int intIDnumber = Convert.ToInt32(txtID.Text);
        
            lblNameFirst.Text = strClient[intIDnumber,0];
            lblNameLast.Text = strClient[intIDnumber,1];
            lblTel.Text = strClient[intIDnumber,2];
        
        }
    
    }

</script>
<html>
<head>
    <title>Array Multidimensional Example</title>
</head>
<body>
    <form runat="server">
        Enter a client number (from 0 to 3) 
        <asp:TextBox runat="server" ID="txtID"></asp:TextBox><br>
        
        <asp:Label id="lblNameFirst" runat="server"></asp:Label><br>
        <asp:Label id="lblNameLast" runat="server"></asp:Label><br>
        <asp:Label id="lblTel" runat="server"></asp:Label><br>
        
        <asp:Button runat="server" Text="Button"></asp:Button>
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Array Reverse Demo (VB.net)
2.For Each loop through an Array (VB.net)
3.Array.IndexOf and Array.LastIndexOf (VB.net)
4.Get array by index (VB.net)
5.Sort an Array (VB.net)
6.For each loop: array (VB.net)
7.Change array length (VB.net)
8.Define and use array (VB.net)
9.Sort array reversely (C#)
10.Get array element by index (C#)
11.Array.IndexOf(), Array.LastIndexOf() (C#)
12.Use String Array to store Asp Label Text (C#)
13.Use array: find item index (C#)