Click here to Skip to main content
13,247,704 members (59,421 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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")
            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()
            ViewState("CurrentTable") = dt
            dg1.DataSource = dt
        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
        End If

    End Sub
End Class

this is the code where i get the error
Posted 1-Feb-13 19:03pm
supriya931 2-Feb-13 3:46am
no i already did this but it sems same problem

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Simple: For i = 4 To dt.Rows.Count + 1 should be For i = 4 To dt.Rows.Count - 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100