必须是非负数且小于集合的大小

必须是非负数且小于集合的大小

本文介绍了ndex超出了范围。必须是非负数且小于集合的大小。参数名称:index的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

otected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            con = New SqlConnection("Data Source=.;Initial Catalog=appraisal;User ID=sa;Password=database")
            addrows()
            dt = New DataTable
            Dim dr As DataRow = Nothing
            dt.Columns.Add("QuesId", GetType(Label))
            dt.Columns.Add("Question", GetType(Label))
            dt.Columns.Add("Option1", GetType(CheckBoxField))
            dt.Columns.Add("Option2", GetType(CheckBoxField))
            dt.Columns.Add("Option3", GetType(CheckBoxField))
            dt.Columns.Add("Option4", GetType(CheckBoxField))
            dr = dt.NewRow()
            dt.Rows.Add(dr)
            ViewState("CurrentTable") = dt
            dg1.DataSource = dt
            dg1.DataBind()

        End If
    End Sub
    'add rows on load event
    Public Sub addrows()
        Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
        Dim drCurrentRow As DataRow = Nothing
        cm = New SqlCommand("SELECT q.ques_id, q.ques_txt, o1.option_id, o1.option_txt FROM ques_mst q INNER JOIN option_mst o1 ON q.ques_id = o1.ques_id where q.ques_id='" & i & "'", con)
        da = New SqlDataAdapter(cm)
        ds = New DataSet
        da.Fill(ds, "ta1")
        dt = New DataTable
        dt = ds.Tables("ta1")
        If dt.Rows.Count > 0 Then
            For i = 4 To dt.Rows.Count + 1
                Dim lq As Label = DirectCast(dg1.Rows(rowindex).Cells(1).FindControl("l_ques"), Label)
                Dim lop1 As Label = DirectCast(dg1.Rows(rowindex).Cells(1).FindControl("l_op1"), Label)
                Dim lop2 As CheckBox = DirectCast(dg1.Rows(rowindex).Cells(1).FindControl("l_op2"), CheckBox)
                Dim lop3 As CheckBox = DirectCast(dg1.Rows(rowindex).Cells(1).FindControl("l_op3"), CheckBox)
                Dim lop4 As CheckBox = DirectCast(dg1.Rows(rowindex).Cells(1).FindControl("l_op4"), CheckBox)
                drCurrentRow = dtCurrentTable.NewRow()
                drCurrentRow("QuesId") = i + 1
                dtCurrentTable.Rows(i - 1)("Column1") = lq.Text
                dtCurrentTable.Rows(i - 1)("Column2") = lop1.Text
                dtCurrentTable.Rows(i - 1)("Column3") = lop2.Text
                dtCurrentTable.Rows(i - 1)("Column3") = lop3.Text
                dtCurrentTable.Rows(i - 1)("Column3") = lop4.Text
                rowindex += 1
            Next
        End If



    End Sub

End Class





这是我得到错误的代码



this is the code where i get the error

推荐答案


这篇关于ndex超出了范围。必须是非负数且小于集合的大小。参数名称:index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 14:28