0

我正在转发器中创建一个学生评估表,该表应该提交评估响应并更新 SQL 数据库,但我不断收到标题中提到的错误。我正在使用 VB 在 ASP.Net 中进行编码。

这是我的代码:Student.aspx

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">

    <asp:Wizard ID="StudentEvaluationWizard" runat="server" ActiveStepIndex="0">
        <WizardSteps>
            <asp:WizardStep ID="WizardStep1" runat="server" Title="Course">
                <asp:GridView ID="CourseView" runat="server" AutoGenerateColumns="False" 
                    DataKeyNames="SectionID" >
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField DataField="EnrollmentID" HeaderText="EnrollmentID" 
                            InsertVisible="False" ReadOnly="True" SortExpression="EnrollmentID" />
                        <asp:BoundField DataField="StudentID" HeaderText="StudentID" 
                            SortExpression="StudentID" />
                        <asp:BoundField DataField="SectionID" HeaderText="SectionID" 
                            SortExpression="SectionID" />
                        <asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Section" >
                            <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Section.Course.Name") %>' ></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </asp:WizardStep>

            <asp:WizardStep ID="WizardStep2" runat="server" Title="Evaluation">
                <asp:Repeater ID="EvalRepeater" runat="server" 
                    DataSourceID="EvaluationQuestions">
                <HeaderTemplate><caption><asp:Label ID="EvaluationTitle" runat="server" Text='<%Eval("Evaluation.Evaluation1.") %>' /><caption></HeaderTemplate>

                <ItemTemplate>
                   <tr>
                <td>
                    <asp:Label ID="QuestionID" runat="server" Text='<%# Eval("QuestionID") %>' Visible="false" />
                </td>
                <td>
                    <asp:Label ID="Questions" runat="server" Text='<%# Eval("Question1") %>' />
                </td>
                <td>
                    <%--Move outside of table to make edits--%>
                    <asp:RadioButtonList ID="Question" runat="server" RepeatDirection="Horizontal">
                        <asp:ListItem Value="1">1</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="5">5</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td>
                <asp:TextBox ID="StudentComment" runat="server" />
                </td>
            </tr>
                </ItemTemplate>
        <FooterTemplate>

            </table>
        </FooterTemplate>
                </asp:Repeater>
                   <asp:Button ID="SubmitButton" runat="server" Text="Submit Evaluation" />
            </asp:WizardStep>
        </WizardSteps>
    </asp:Wizard>

    <asp:LinqDataSource ID="CourseSelect" runat="server" ContextTypeName="EvaluationDAL.Model.EvaluationDataDataContext"
        EntityTypeName="Enrollment" TableName="Enrollments" Where="StudentID == @StudentID">
        <WhereParameters>
            <asp:SessionParameter DefaultValue="StudentID" Name="StudentID" SessionField="StudentID"
                Type="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>

    <asp:LinqDataSource ID="EvaluationQuestions" runat="server" ContextTypeName="EvaluationDAL.Model.EvaluationDataDataContext"
        EntityTypeName="" TableName="Questions" 
        Where="EvaluationID == Convert.ToInt32(@EvaluationID)">
        <WhereParameters>
            <asp:SessionParameter Name="EvaluationID" SessionField="EvaluationID" 
                Type="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>
</asp:Content>

Student.aspx.vb(有错误的提交按钮)

 Protected Sub SubmitButton_Click(sender As Object, e As System.EventArgs) Handles SubmitButton.Click

        Dim sr As New StudentEvaluation
        sr.SectionID = EvaluationGlobal.SectionID
        sr.EvaluationDate = DateAndTime.Now


        'Create a new evaluation object
        Dim eval As New StudentEvaluation


        For Each row As RepeaterItem In EvalRepeater.Items
            'Get the question
            Dim questionID As Label = CType(row.FindControl("QuestionID"), Label)
            Dim question1 As Integer = Convert.ToInt32(question1)

            eval.Comments = Convert.ToInt32(row.FindControl("Comments"))

            'Find radio button list with the name Question and convert to radio button list
            Dim rank As RadioButtonList = CType(row.FindControl("Question"), RadioButtonList)

            'Get the infomation if the area is not empty
            If Not String.IsNullOrWhiteSpace(rank.SelectedValue) Then
                Dim ser As New StudentEvaluationResponse
                ser.QuestionID = Convert.ToInt32(row.FindControl("QuestionID"))
                ser.Answer = Convert.ToInt16(row.FindControl("Question"))

                Dim questionRank As Integer = Convert.ToInt32(rank.SelectedValue)
                Dim studentComment As TextBox = CType(row.FindControl("StudentComment"), TextBox)
                Dim comment As String = studentComment.Text
                eval.StudentEvaluationResponses.Add(ser)

            End If
        Next
        If eval.StudentEvaluationResponses.Count > 0 Then
            eval.Insert()
        End If
    End Sub

我完全不知道如何解决这个问题。任何帮助都是极好的。

4

1 回答 1

3

这看起来是错误的开始:

Dim question1 As Integer = Convert.ToInt32(question1)

怀疑你的意思是:

Dim question1 As Integer = Convert.ToInt32(questionID.Text)

同样,我怀疑这些:

ser.QuestionID = Convert.ToInt32(row.FindControl("QuestionID"))
ser.Answer = Convert.ToInt16(row.FindControl("Question"))

应该使用以下Text属性:

ser.QuestionID = Convert.ToInt32(CType(row.FindControl("QuestionID"), Label).Text)
ser.Answer = Convert.ToInt16(CType(row.FindControl("Question"), RadioButton).Text)

这样你就试图转换控件的文本,而不是控件本身。

于 2012-05-02T03:40:31.490 回答