Use array: find item index (C#) : Array « Collections « ASP.Net






Use array: find item index (C#)

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

void Page_Load(){
   if (Page.IsPostBack){
       string[] choice = new string[3];
       choice[0] = "1";
       choice[1] = "2";
       choice[2] = "3";

       lblShipper.Text = "Shipper ID for " + txtShipNum.Text + " is " + Array.IndexOf(choice, txtShipNum.Text);
       lblShipper.Visible = true;
   }
}

</script>
<html>
<head>
    <title>Array Example</title>
</head>
<body>
    <form runat="server">
        Please enter your shipper name. 
        (should be "1"  or  "2"  or  "3") 
        <br><asp:TextBox id="txtShipNum" runat="server" width="300px"></asp:TextBox>
        <br />
        Press button to find the Shipper ID number
        <asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
        <br />
        <asp:Label id="lblShipper" runat="server"></asp:Label>
    </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 Two dimensional array (C#)