在我的动态复选框控件中,当我将它放入For循环中以基于数据值创建控件时,它显示异常错误 [英] In My Dynamic Check Box Control, When I Put It In A For Loop To Create Control Based On Datatable Values, It Shows An Exception Error

查看:39
本文介绍了在我的动态复选框控件中,当我将它放入For循环中以基于数据值创建控件时,它显示异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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"..

推荐答案

你循环的j是多少行,但是用作单元格的索引!!!
You loop for j is over number of rows, but used as an index for cells!!!


我在页面预加载时创建了模板字段,然后在页面加载事件中添加复选框。它运作良好..
I have created the Template field at the Page Preload, then add the check box in the page load event. its working well..


这篇关于在我的动态复选框控件中,当我将它放入For循环中以基于数据值创建控件时,它显示异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆