Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2005, 12:11 PM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to load values to dropdob menue from table

Hi expert . I want to make the teamno and playerno feilds as a drop down box that have their values from the table.



Code:
     <td nowrap>TEAMNO: </td>

             <td><input type="text" id="TEAMNO" value="0000" runat="server"></td>

            </tr> 

            <tr nowrap>

             <td>Playerno: </td>

             <td><input type="text" id="PLAYERNO" value="0000" runat="server"></td>
i be happy if some one help me put dropdon menue instead of text box for teamno and playerno.Thanks



Code:
 

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>

 

<html>

<script language="VB" runat="server">

 

    Dim MyConnection As SqlConnection

 

    Sub Page_Load(Sender As Object, E As EventArgs) 

 

        MyConnection = New SqlConnection("server=(local);database=teniss2;User Id=web;Password=web;")

 

        If Not (IsPostBack)

            BindGrid()

        End If

    End Sub

 

    Sub Addmatches_Click(Sender As Object, E As EventArgs) 

 

        Dim DS As DataSet

        Dim MyCommand As SqlCommand

 

        If MATCHNO.Value = "" Or TEAMNO.Value = "" Or PLAYERNO.Value = "" Or WON.Value = ""

 

         Message.InnerHtml = "ERROR: Null values not allowed "

         Message.Style("color") = "red"

         BindGrid()

        End If

 

        Dim InsertCmd As String = "insert into matches (MATCHNO, TEAMNO, PLAYERNO ,WON, LOST) values (@LMATCHNO, @LTEAMNO, @LPLAYERNO, @LWON, @LLOST)"

 

        MyCommand = New SqlCommand(InsertCmd, MyConnection)

 

        MyCommand.Parameters.Add(New SqlParameter("@LMATCHNO", SqlDbType.NVarChar, 11))

        MyCommand.Parameters("@LMATCHNO").Value = Server.HtmlEncode(MATCHNO.Value)

 

        MyCommand.Parameters.Add(New SqlParameter("@LTEAMNO", SqlDbType.NVarChar, 40))

        MyCommand.Parameters("@LTEAMNO").Value = Server.HtmlEncode(TEAMNO.Value)

 

        MyCommand.Parameters.Add(New SqlParameter("@LPLAYERNO", SqlDbType.NVarChar, 20))

        MyCommand.Parameters("@LPLAYERNO").Value = Server.HtmlEncode(PLAYERNO.Value)

 

        MyCommand.Parameters.Add(New SqlParameter("@LWON", SqlDbType.NChar, 12))

        MyCommand.Parameters("@LWON").Value = Server.HtmlEncode(WON.Value)

 

        MyCommand.Parameters.Add(New SqlParameter("@LLOST", SqlDbType.NVarChar, 40))

        MyCommand.Parameters("@LLOST").Value = Server.HtmlEncode(LOST.Value)

 

 

 

        MyCommand.Connection.Open()

 

        Try 

            MyCommand.ExecuteNonQuery()

            Message.InnerHtml = "<b>Record Added</b><br>" & InsertCmd.ToString()

 

        Catch Exp As SQLException

            If Exp.Number = 2627

                Message.InnerHtml = "ERROR: A record already exists with the same primary key"

            Else

                Message.InnerHtml =Exp.Message

            End If

            Message.Style("color") = "red"

 

        End Try

 

        MyCommand.Connection.Close()

 

        BindGrid()

    End Sub

 

    Sub BindGrid() 

 

        Dim MyCommand As SqlDataAdapter = new SqlDataAdapter("select * from matches", MyConnection)

 

        Dim DS As DataSet = new DataSet()

        MyCommand.Fill(DS, "matches")

 

        MyDataGrid.DataSource=DS.Tables("matches").DefaultView

        MyDataGrid.DataBind()

    End Sub

 

</script>

 

<body style="font: 10pt verdana">

 

<form runat="server">

 

    <h3>Inserting A MATCHES RECORD</h3>

 

    <table width="95%">

     <tr>

        <td valign="top">

 

         <ASPataGrid id="MyDataGrid" runat="server"

            Width="700"

            BackColor="#ccccff" 

            BorderColor="black"

            ShowFooter="false" 

            CellPadding=3 

            CellSpacing="0"

            Font-Name="Verdana"

            Font-Size="8pt"

            HeaderStyle-BackColor="#aaaadd"

            EnableViewState="false"

         />

 

        </td>

        <td valign="top">

 

         <table style="font: 8pt verdana">

            <tr>

             <td colspan="2" bgcolor="#aaaadd" style="font:10pt verdana">Add a New record:</td>

            </tr>

            <tr>

             <td nowrap>MATCHNO: </td>

             <td><input type="text" id="MATCHNO" value="0000" runat="server"></td>

            </tr>

            <tr>

             <td nowrap>TEAMNO: </td>

             <td><input type="text" id="TEAMNO" value="0000" runat="server"></td>

            </tr> 

            <tr nowrap>

             <td>Playerno: </td>

             <td><input type="text" id="PLAYERNO" value="0000" runat="server"></td>

            </tr>

            <tr>

             <td>Won: </td>

             <td><input type="text" id="WON" value="0000" runat="server"></td>

            </tr>

            <tr>

             <td>Lost: </td>

             <td><input type="text" id="LOST" value="0000" runat="server"></td>

            </tr>

 

             <td></td>

             <td style="padding-top:15">

                <input type="submit" OnServerClick="Addmatches_Click" value="Add matches" runat="server">

             </td>

            </tr>

            <tr>

             <td colspan="2" style="padding-top:15" align="center">

                <span id="Message" EnableViewState="false" style="font: arial 11pt;" runat="server"/>

             </td>

            </tr>

         </table>

 

        </td>

     </tr>

    </table>

 

</form>

 

</body>

</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Control State to save/load values VictorVictor ASP.NET 2.0 Professional 0 March 29th, 2007 03:14 PM
how to create tool bar menue in access method Access VBA 1 June 18th, 2005 10:14 AM
load values into the dataset from the xml dhol General .NET 2 December 31st, 2004 06:37 AM
load values into the dataset from the xml dhol XML 1 December 31st, 2004 05:34 AM
how to load data into a table? hosefo81 PHP Databases 3 November 3rd, 2003 02:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.