Mega Code Archive

 
Categories / ASP.Net / Collections
 

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>