检查动态创建的复选框列表中是否已经存在新数据 [英] Check if new data is already exist in dynamic-created-checkboxlist

查看:59
本文介绍了检查动态创建的复选框列表中是否已经存在新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面加载时创建了一个动态复选框(不是isPostback)

现在,如果要插入新数据,则系统应首先检查所创建的复选框列表中是否已存在该数据.

我已经尝试过了,但是发生了错误

I created a dynamic checkbox at Page Load (Not isPostback)

Now if a new data is to be inserted, the system should check first whether the data is already exist in the created checkboxlist.

i have tried this, but error occured

Object reference not set to an instance of an object.



这是我的代码.



This is my code.

Dim row As DataRow = dt.NewRow()

  Dim chlist As CheckBoxList = DirectCast(FindControl("cbTest"), CheckBoxList)
      For i = 0 To dtSH.Rows.Count - 1

        For Each Listdata As ListItem In chlist.Items

            For Each row1 As DataRow In dt.Rows

               If dtSH.Rows(i)("EMPID_T") <> row1("EMPID_T").ToString Then
                             row = dt.NewRow()
                             row("EMPID_T") = dtSH.Rows(i)("EMPID_T")
                             row("NAME_T") = dtSH.Rows(i)("NAME_T")
                             dt.Rows.Add(row)
                         End If

                     Next
                 Next

             Next



我不知道这里是否



i dont know whether here

Dim chlist As CheckBoxList = DirectCast(FindControl("cbTest"), CheckBoxList)

或此处

For Each Listdata As ListItem In chlist.Items


这是错误的.请给我一点帮助. TQ!


that goes wrong. A little help please. TQ!

推荐答案

对象引用未设置为对象的实例

当您尝试使用属性或调用对象的方法为null时,会发生此错误.更多详细信息:此处 [
Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.


i的声明在哪里?



如果有帮助,请标记为答案. :)
where is the declaration of i?



mark as answer if it helped you. :)


这篇关于检查动态创建的复选框列表中是否已经存在新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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