2012-05-02 163 views
0

を入力して、私は評価の回答を提出し、SQLデータベースを更新する必要があり、リピータにおける学生の評価フォームを作成しています、私はタイトルに記載されているエラーを取得し続けます。私はVBでASP.Netでコーディングしています。型のオブジェクトをキャストすることができません「System.Web.UI.WebControls.Label」「System.IConvertible」

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 

私は完全にこの問題を解決する方法に迷ってしまいました(エラーで送信ボタン) 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:

は、ここに私のコードです。どんな助けも素晴らしいだろう。

答えて

2

これで始まるのは間違いになります。

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) 

このようにして、コントロール自体のテキストではなく、コントロールのテキストを変換しようとしています。

+0

QuestionIDは修正されましたが、回答セクションにエラーが発生しました。これはラジオボタンのリストで、ラベルではないからだと思います。私はこれまで、それを変更する必要があります。 ser.Answer = Convert.ToInt16(ctype関数(row.FindControl( "質問")、ラジオボタン) –

+0

@DaniMoss:あなたはまだだけでなく、ラジオボタン自体のRadioButtonのプロパティを使用する必要があります。 。それはあなたがあなたの代わりにラジオボタンのRadioButtonListのを意味するものではありませんことを確認しているが使用したいプロパティはっきりしていない –

+0

だからコードは次のようになります? ser.Answer = Convert.ToInt16(ctype関数(row.FindControl(「質問」) 、Checked)RadioButton) –

関連する問題