Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
Posted 1-Feb-13 18:03pm
Comments
supriya931 at 2-Feb-13 3:46am
   
no i already did this but it sems same problem

1 solution

Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 375
1 _Amy 235
2 Andreas Gieriet 180
3 Peter Leow 175
4 Dave Kreskowiak 155
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,462
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2014
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