Dropdownlist,DataTextField,DataValueField ?

Discussion in 'ASP .Net' started by Sam, Feb 18, 2005.

  1. Sam

    Sam Guest

    I want to create dropdownlist where DataTextField and DataValueField are
    extract from table gldate.

    Example
    Dropdownlist -> Jan-2005
    -> Feb-2005
    ...
    ...
    -> Dec-2005

    Table gldate
    ============
    DataTextField DataValueField
    --------------------------------
    Jan-2005 200501
    Feb-2005 200502
    .... ...
    .... ...
    Dec-2005 200512


    Error
    =====
    Description: An error occurred during the compilation of a resource required
    to service this request. Please review the following specific error details
    and modify your source code appropriately.

    Compiler Error Message: BC30188: Declaration expected.

    Source Error:
    Line 5: Dim cnSQL as New System.Data.SqlClient.SqlConnection()
    Line 6:
    Line 7: cnSQL.ConnectionString = "Password=88;Persist Security Info=True;
    User ID=88;Initial Catalog=JDE_ERP_ARCHIVAL;Data Source=SQLSVR"
    Line 8:
    Line 9: cnSQL.Open()

    Source File: C:\Documents and Settings\samuellai\My
    Documents\Header\NewFile.aspx Line: 7


    Search.aspx
    ===========
    <%@ Page Language="VB" %>
    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.SqlClient" %>
    <script runat="server">
    Dim cnSQL as New System.Data.SqlClient.SqlConnection()

    cnSQL.ConnectionString = "Password=88;Persist Security Info=True; User
    ID=88;Initial Catalog=JDE_ERP_ARCHIVAL;Data Source=SQLSVR"

    cnSQL.Open()

    Dim GLDate as New SQLCommand ("select * from gldate",cnSQL)

    Dim dr as SQLDataReader = GLDate.ExecuteReader

    Do While dr.Read

    End DO

    dr.Close
    GLDate = Nothing
    dr = Nothing

    </script>
    <html>
    <head>
    </head>
    <body>
    <form runat="server">
    <asp:DropDownList id="DropDownList1" runat="server"
    OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" DataSource="<%#
    SqlDataSourceControl2 %>" DataTextField="gl_date"
    DataValueField="gl_date"></asp:DropDownList>
    </form>
    </body>
    </html>


    Please advise.

    Many thanks.
     
    Sam, Feb 18, 2005
    #1
    1. Advertising

  2. A server script on the page can contain member declarations only, in the
    same way as a class can. You should declare a method and put he code inside
    the method.

    Eliyahu

    "Sam" <> wrote in message
    news:O5%...
    > I want to create dropdownlist where DataTextField and DataValueField are
    > extract from table gldate.
    >
    > Example
    > Dropdownlist -> Jan-2005
    > -> Feb-2005
    > ...
    > ...
    > -> Dec-2005
    >
    > Table gldate
    > ============
    > DataTextField DataValueField
    > --------------------------------
    > Jan-2005 200501
    > Feb-2005 200502
    > ... ...
    > ... ...
    > Dec-2005 200512
    >
    >
    > Error
    > =====
    > Description: An error occurred during the compilation of a resource

    required
    > to service this request. Please review the following specific error

    details
    > and modify your source code appropriately.
    >
    > Compiler Error Message: BC30188: Declaration expected.
    >
    > Source Error:
    > Line 5: Dim cnSQL as New System.Data.SqlClient.SqlConnection()
    > Line 6:
    > Line 7: cnSQL.ConnectionString = "Password=88;Persist Security Info=True;
    > User ID=88;Initial Catalog=JDE_ERP_ARCHIVAL;Data Source=SQLSVR"
    > Line 8:
    > Line 9: cnSQL.Open()
    >
    > Source File: C:\Documents and Settings\samuellai\My
    > Documents\Header\NewFile.aspx Line: 7
    >
    >
    > Search.aspx
    > ===========
    > <%@ Page Language="VB" %>
    > <%@ import Namespace="System.Data" %>
    > <%@ import Namespace="System.Data.SqlClient" %>
    > <script runat="server">
    > Dim cnSQL as New System.Data.SqlClient.SqlConnection()
    >
    > cnSQL.ConnectionString = "Password=88;Persist Security Info=True; User
    > ID=88;Initial Catalog=JDE_ERP_ARCHIVAL;Data Source=SQLSVR"
    >
    > cnSQL.Open()
    >
    > Dim GLDate as New SQLCommand ("select * from gldate",cnSQL)
    >
    > Dim dr as SQLDataReader = GLDate.ExecuteReader
    >
    > Do While dr.Read
    >
    > End DO
    >
    > dr.Close
    > GLDate = Nothing
    > dr = Nothing
    >
    > </script>
    > <html>
    > <head>
    > </head>
    > <body>
    > <form runat="server">
    > <asp:DropDownList id="DropDownList1" runat="server"
    > OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

    DataSource="<%#
    > SqlDataSourceControl2 %>" DataTextField="gl_date"
    > DataValueField="gl_date"></asp:DropDownList>
    > </form>
    > </body>
    > </html>
    >
    >
    > Please advise.
    >
    > Many thanks.
    >
    >
     
    Eliyahu Goldin, Feb 18, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parodi Development
    Replies:
    0
    Views:
    3,693
    Parodi Development
    Sep 10, 2004
  2. nicholas
    Replies:
    5
    Views:
    15,761
    nicholas
    Dec 3, 2004
  3. tshad
    Replies:
    3
    Views:
    4,659
    tshad
    May 10, 2005
  4. Eric W. Holzapfel

    Access DropDownlist datavaluefield value

    Eric W. Holzapfel, Jan 1, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    16,211
    =?Utf-8?B?RWx0b24gVw==?=
    Jan 1, 2006
  5. jobs
    Replies:
    0
    Views:
    499
Loading...

Share This Page