Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: validation for dropdownlist


Message #1 by anirose_US@y... on Thu, 15 Aug 2002 17:58:17
Hi friend:
Here is an exaple for u:
_____________________________________
<script language="C#" runat="server">
  void btnSubmit_Click(Object sender, EventArgs e)
  {
    if (Page.IsValid)
      Response.Write("<i><b>Your favorite food is " +
            lstFood.SelectedItem.Value + "!!</b></i>");
  }
</script>

<html>
<body>
  <form method="post" runat="server">
    What is your favorite food?
    <asp:DropDownList id="lstFood" runat="server">
      <asp:ListItem>--Select a Food--</asp:ListItem>
      <asp:ListItem>Cookies</asp:ListItem>
      <asp:ListItem>Tuna Roll</asp:ListItem>
      <asp:ListItem>Popcorn Shrimp</asp:ListItem>
      <asp:ListItem>Liver and Onions</asp:ListItem>
    </asp:DropDownList>

    <asp:RequiredFieldValidator runat="server"
          id="reqFood" ControlToValidate="lstFood"
          ErrorMessage="You must select a favorite food!"
          InitialValue="--Select a Food--" />

    <p><asp:button id="btnSubmit" runat="server"
            OnClick="btnSubmit_Click" Text="Next -->" />
  </form>
</body>
</html>
__________________________________
Hope i'll help u,
Hovik



  Return to Index