Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: beginners question


Message #1 by Greg Partin <GPartin@c...> on Thu, 28 Mar 2002 10:22:54 -0500
Hi folks, 

I'm new to .Net website programming and have a simple question.  I'm just
trying to create a page that has 3 drop down menus and a submit button.  The
3 drop down menus are controls that are included on a web form.  The 'code
behind' page generates the drop down menus.  After the user hits submit I
have some code on the web form that does a sql query and prints the records
into a data form.  Here's the code:

<%@Import NameSpace="System.Data" %> 
<%@Import NameSpace="System.Data.SqlClient" %> 
<%@ Register Tagprefix="CLO" TagName="ClassProgressSubjectDropDown"
src="SubjectDropDown.ascx" %> 
<%@ Register Tagprefix="CLO" TagName="ClassProgressClassDropDown"
src="ClassDropDown.ascx" %> 
<%@ Register Tagprefix="CLO" TagName="ClassProgressScoreFilter"
src="ScoreFilter.ascx" %> 
<%@ OutputCache Duration="20" VaryByParam="*" %> 
<%@ Page Language="VB" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
        <HEAD> 
                <title>Class Progress Report</title> 
                <script runat="server"> 
        Sub btnSubmit_Click(sender as object, e as eventargs) 
        
                Dim myConnection As SqlConnection 
        Dim myCommand As SqlCommand 
        Dim myReader As SqlDataReader 
        Dim SQL As String 
        Dim ConnStr As String 

        ConnStr = "server=CHILDU-LAB1;database=TLO;UID=TLO;PWD=tlo" 
        SQL = "SELECT " & _ 
                                "Class_ID, Test_ID, Content_Standard_ID,
Grade_Cd, Subject_Cd, Test_title, Content_Standard_Description,
Display_Order, " & _

                                "Num_students_taken, Num_Mastered,
Num_Not_Mastered " & _ 
                          "FROM " & _ 
                                "Class_Report "& _ 
                          "WHERE " & _ 
                                "class_id = 1 " & _ 
                          "AND " & _ 
                                "subject_cd = '" &
Subject.SelectedIndex.Value & "' " & _ 
                          "ORDER BY " & _ 
                                "grade_cd, display_order" 
                
        Try 
            myConnection = New SqlConnection(ConnStr) 
            myConnection.Open() 
            myCommand = New SqlCommand(SQL, myConnection) 
            myReader = myCommand.ExecuteReader() 
            dgrResult.DataSource = myReader 
            dgrResult.DataBind() 
        Catch ex As Exception 
            Throw New Exception(ex.ToString()) 
        Finally 
        End Try 

        End Sub 
                </script> 
                <meta content="Microsoft Visual Studio.NET 7.0"
name="GENERATOR"> 
                <meta content="Visual Basic 7.0" name="CODE_LANGUAGE"> 
                <meta content="JavaScript" name="vs_defaultClientScript"> 
                <meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema"> 
        </HEAD> 
        <body MS_POSITIONING="GridLayout"> 
                <P><br> 
                        <br> 
                        <IMG src="header.bmp"></P> 
                <P align="center">Class Progress Report</P> 
                <form id="frmClassProgress" action="WebForm2.aspx"
method="post" runat="server"> 
                        <CLO:CLASSPROGRESSSUBJECTDROPDOWN
id="ClassProgressSubjectDropDown"
runat="server"></CLO:CLASSPROGRESSSUBJECTDROPDOWN>

                        <CLO:CLASSPROGRESSCLASSDROPDOWN
id="ClassProgressClassDropDown"
runat="server"></CLO:CLASSPROGRESSCLASSDROPDOWN>

                        <CLO:CLASSPROGRESSSCOREFILTER
id="ClassProgressScoreFilter" runat="server"></CLO:CLASSPROGRESSSCOREFILTER>

                        <asp:button id="btnSubmit" style="Z-INDEX: 101;
LEFT: 360px; POSITION: absolute; TOP: 280px" onclick="btnSubmit_Click"
Runat="server" Text="Submit"></asp:button>

                </form> 
                <asp:datagrid id="dgrResult" style="Z-INDEX: 102; LEFT:
18px; POSITION: absolute; TOP: 355px" Runat="server"></asp:datagrid>

        </body> 
</HTML> 

The part it is bombing on is where I try to reference
Subject.SelectedIndex.Value to dynamically create the SQL statement.

Here is the component code: 

<%@ Control Language="vb" Codebehind="SubjectDropDown.ascx.vb"
Inherits="WebApplication1.SubjectDropDown" AutoEventWireup="false"%>

<asp:Label id="Label1" Width="161px" runat="server">Subject</asp:Label> 
<asp:DropDownList id="Subject" DataTextField="description"
DataValueField="subject_cd" runat="server"> 
</asp:DropDownList> 



The codebehind stuff works because if i put a static value in the SQL
statement the page works.  Any help would be greatly appreciated.  If the
error page that I get is needed for help on debugging I will post it, but
the error message makes no sense to me.

thanks in advance, 

Greg 

  

  Return to Index