Click here to Skip to main content
15,921,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
For Each row As GridViewRow In gv.Rows
            If row.RowType = DataControlRowType.DataRow Then
                For j = 0 To dtop.Rows.Count - 1
                    Dim tf As New TemplateField()
                    Dim cb As New CheckBox
                    tf.HeaderText = "" & dtop.Rows(j)(0) & ""
                    gv.Columns.Add(tf)
                    row.Cells(j + 1).Controls.Add(cb)
                Next
            End If

        Next



row.Cells(j + 1).Controls.Add(cb). The exception is on this line and the exception is "Specified argument was out of the range of valid values. Parameter name: index"..
Posted

You loop for j is over number of rows, but used as an index for cells!!!
 
Share this answer
 
Comments
R@M-ITcian 14-May-14 6:12am    
But binding the control on grid is based on the datatable values which i referred for loop in j
Kornfeld Eliyahu Peter 14-May-14 6:25am    
You have to read carefully your code and my answer - you just missing the main point of mixing rows and cells!!!
R@M-ITcian 14-May-14 6:55am    
Hey buddy listen my coding, those dtop is a datatable. Just its used for looping to fix how many no. of dynamic columns and control for gridview cells. Final code line is to add the control to gridview cells.
Kornfeld Eliyahu Peter 14-May-14 7:01am    
Not good! Try again!
I have created the Template field at the Page Preload, then add the check box in the page load event. its working well..
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900