本文介绍了从动态创建的复选框列表中选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我动态创建了一个复选框列表(cbSh)以列出一些员工数据.
我试图声明这样的内容:
I created a checkboxlist (cbSh) dynamically to list some employee data.
I have tried to declare something like this:
Dim checklist As CheckBoxList = CType(FindControl("cbSh"), CheckBoxList)
发生的错误是
the error occured is
Unable to cast object of type ''System.Web.UI.WebControls.CheckBox'' to type ''System.Web.UI.WebControls.CheckBoxList''
我应该在哪里修改代码,以便能够找到我的复选框列表并获取所选值?
谢谢您的宝贵时间.
UPDATED>>>
这是创建复选框列表的代码.
Where should I modify my code to be able finding my checkboxlist and getting the selected value?
Thanks for your time.
UPDATED>>>
This is the code to create checkboxlist.
Dim sqlGetPrdNme As String = "SELECT * FROM Q_VIEWDATA WHERE REFNO_T = '201207-1i' AND PRDNAME_T NOT IN ('QA','SEP','OTH')"
Dim SHprodName As DataTable = DBLayer.Util.Data.MsSql.DBFunction.BuildDataTable(sqlGetPrdNme, DBLayer.ClsConnection.getConnString("MP_QFMS"))
For Each dr As DataRow In SHprodName.Rows
Dim TempPanel As New Panel
TempPanel.Width = 210
TempPanel.Height = 300
TempPanel.HorizontalAlign = HorizontalAlign.Center
TempPanel.BorderStyle = BorderStyle.Solid
Dim labelProd As New Label
labelProd.Font.Bold = True
labelProd.ForeColor = Drawing.Color.Red
labelProd.Text = dr("PRDNAME_T")
Dim labelP As New Label
labelP.Font.Bold = True
labelP.ForeColor = Drawing.Color.Red
labelP.Text = dr("PRDNAME_T")
Dim lit As New Literal
lit.Text = "</b></br>"
Dim sqlShophead As String = "SELECT DISTINCT list3.DEPTID_T, list3.CSCTRNM_T, list3.NEW_COST_CTR_T, sh.EMPID_" & _
"T, sh.NAME_T FROM (SELECT list1.DEPTID_T, list1.CSCTRNM_T, list2.NEW_COST_CTR_T " & _
"FROM (SELECT DEPTID_T, CSCTRNM_T FROM dbo.Q_HR_PAYROL_SECTION_SHOP_DTLS WHERE (P" & _
"LANTID_T = 'D01' OR PLANTID_T = 'D06') AND (CSCTRFLAG_T = 'Y')) AS list1 LEFT OU" & _
"TER JOIN (SELECT OLD_COST_CTR_T, NEW_COST_CTR_T, ACTIVE_FLAG_B, CSCTRNM_T, CSCTR" & _
"DESC_T, PLANTID_T, CSCTRFLAG_T, COST_CENTRE_T, INTERNAL_ORDER_T, PROFIT_CENTRE_T" & _
", CSCTRNAME_T, ISCHARGE_TO_AD_T, PLANTID_CODE_T, PLANTDESC_T FROM dbo.Q_COSTCENT" & _
"RE WHERE (CSCTRFLAG_T = 'y')) AS list2 ON list1.CSCTRNM_T = list2.CSCTRNM_T) AS " & _
"list3 INNER JOIN (SELECT EMPID_T, NAME_T, CSCTRID_T, STATUS_T, JOBTITLE_T FROM E" & _
"PJ_Employee.dbo.EMPLOYEE_DATA WHERE (STATUS_T <> '*') AND (JOBTITLE_T LIKE '%SHO" & _
"PHEAD%') AND (ORIGINID_T = EMPID_T)) AS sh ON list3.NEW_COST_CTR_T = sh.CSCTRID_" & _
"T WHERE (list3.DEPTID_T = '" + dr("PRDNAME_T") + "') "
Dim dtShophead As DataTable = DBLayer.Util.Data.MsSql.DBFunction.BuildDataTable(sqlShophead, DBLayer.ClsConnection.getConnString("Maintenance"))
Dim cbSh As New CheckBoxList
cbSh.DataSource = dtShophead
cbSh.DataValueField = "EMPID_T"
cbSh.DataTextField = "NAME_T"
cbSh.DataBind()
Dim sqlManager As String = "SELECT DISTINCT list3.DEPTID_T, list3.CSCTRNM_T, list3.NEW_COST_CTR_T," & _
" mgr.EMPID_T, mgr.NAME_T FROM (SELECT list1.DEPTID_T, list1.CSCTRNM_T," & _
" list2.NEW_COST_CTR_T FROM (SELECT DEPTID_T, CSCTRNM_T FROM dbo.Q_HR_P" & _
"AYROL_SECTION_SHOP_DTLS WHERE (PLANTID_T = 'D01' OR PLANTID_T = 'D06')" & _
" AND (CSCTRFLAG_T = 'Y')) AS list1 LEFT OUTER JOIN (SELECT OLD_COST_CT" & _
"R_T, NEW_COST_CTR_T, ACTIVE_FLAG_B, CSCTRNM_T, CSCTRDESC_T, PLANTID_T," & _
" CSCTRFLAG_T, COST_CENTRE_T, INTERNAL_ORDER_T, PROFIT_CENTRE_T, CSCTRN" & _
"AME_T, ISCHARGE_TO_AD_T, PLANTID_CODE_T, PLANTDESC_T FROM dbo.Q_COSTCE" & _
"NTRE WHERE (CSCTRFLAG_T = 'y')) AS list2 ON list1.CSCTRNM_T = list2.CS" & _
"CTRNM_T) AS list3 INNER JOIN (SELECT EMPID_T, NAME_T, CSCTRID_T, STATU" & _
"S_T, JOBTITLE_T FROM EPJ_Employee.dbo.EMPLOYEE_DATA WHERE (STATUS_T <>" & _
" '*') AND (JOBTITLE_T LIKE '%MANAGER%') AND (JOBTITLE_T <> 'ASST. GENE" & _
"RAL MANAGER') AND (ORIGINID_T = EMPID_T)) AS mgr ON list3.NEW_COST_CTR" & _
"_T = mgr.CSCTRID_T WHERE (list3.DEPTID_T = '" + dr("PRDNAME_T") + "') "
Dim dtMgr As DataTable = DBLayer.Util.Data.MsSql.DBFunction.BuildDataTable(sqlManager, DBLayer.ClsConnection.getConnString("Maintenance"))
Dim cbMgr As New CheckBoxList
cbMgr.DataSource = dtMgr
cbMgr.DataValueField = "EMPID_T"
cbMgr.DataTextField = "NAME_T"
cbMgr.DataBind()
PlaceHolder1.Controls.Add(labelP)
'PlaceHolder1.Controls.Add(lit)
PlaceHolder1.Controls.Add(cbSh)
PlaceHolder1.Controls.Add(lit)
PlaceHolder2.Controls.Add(labelProd)
PlaceHolder2.Controls.Add(cbMgr)
PlaceHolder2.Controls.Add(lit)
推荐答案
这篇关于从动态创建的复选框列表中选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!