本文介绍了动态复选框单击时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
这是我的方案:
1.我创建了一个动态表。
2.在该表中,我创建了动态面板
3.在面板中,有一个动态复选框。
我想为该复选框添加属性。
以下是我的代码:
Hi all
Here is my scenario:
1. I create a dynamic table.
2. Inside that table, I create dynamic panel
3. Inside the panel, there is a dynamic checkbox.
I want to add attributes for that checkbox.
Below is my code:
For Each drCab As DataRow In dt.Rows
Dim TempPanelrack As New Panel
Dim BtnCab As New Button
Dim chkcab As New CheckBox
TempPanelrack.HorizontalAlign = HorizontalAlign.Center
TempPanelrack.BorderStyle = BorderStyle.Inset
TempPanelrack.Width = 110
TempPanelrack.Height = 80
TempPanelrack.ID = drCab("REFNO_T")
BtnCab.Text = drCab("REFNO_T") & vbCrLf & "(" & CStr(drCab("NAME_T")).Substring(0, 12) & ")" & vbCrLf & "-" & CDate(drCab("FRDATETIME_D")).ToString("HH:mm") & "-"
BtnCab.BorderStyle = BorderStyle.Groove
BtnCab.ToolTip = drCab("NAME_T") & vbCrLf & "From: " & CDate(drCab("FRDATETIME_D")).ToString("dd/MM/yyyy HH:mm:ss") & vbCrLf & " To: " & CDate(drCab("TODATETIME_D")).ToString("dd/MM/yyyy HH:mm:ss") & " "
BtnCab.Attributes.Add("onclick", "Showdetails(''" & drCab("REGISNO_T") & "'');")
BtnCab.Width = 110
BtnCab.Height = 80
BtnCab.Font.Size = 8
BtnCab.Font.Bold = True
chkcab.ToolTip = drCab.Item("REFNO_T")
chkcab.BorderStyle = BorderStyle.None
chkcab.ID = drCab.Item("REFNO_T")
chkcab.Attributes.Add("onClick", "chkcabchecked(''" & TempPanelrack.ID & "'');")
TempPanelrack.Controls.Add(BtnCab)
TempPanelrack.Controls.Add(chkcab)
Dim TC As New TableCell()
TC.Controls.Add(TempPanelrack)
TR.Cells.Add(TC)
If CountCab Mod 4 = 0 Then
Me.tableALL.Rows.Add(TR)
TR = New TableRow()
Else
Me.tableALL.Rows.Add(TR)
End If
Private Sub chkcabchecked(ByVal panelid As String)
'Dim chkbox As CheckBox = CType(sender, CheckBox)
'MsgBox(sender.ID)
Dim mainContent As ContentPlaceHolder = DirectCast(Me.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
'Dim chkcontrol As Panel = DirectCast(mainContent.FindControl("Panel1"), Panel)
Dim tr As Table = DirectCast(mainContent.FindControl("tableALL"), Table)
Dim trpanels As Panel = DirectCast(tr.FindControl(panelid), Panel)
Dim chkbox As CheckBox = DirectCast(trpanels.FindControl("chkcab"), CheckBox)
If (Not chkbox Is Nothing) Then
' Get control's parent.
'Dim chkcontrol2 As Control = chkcontrol.Parent
MsgBox("Parent of the text box is : " & chkbox.ID)
Else
MsgBox("Control not found.....")
End If
End Sub
但是,点击复选框时出现的错误
是:
However, the error
that I get when I click on the checkbox is:
Microsoft JScript runtime error: ''chkcabchecked'' is undefined
推荐答案
这篇关于动态复选框单击时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!