使用变量设置CType控件ID
问题描述:
我在写一个小的子例程,因此它动态地填充了DropDownLists。使用变量设置CType控件ID
但是,当涉及到使用变量传递控件ID时,我不确定是否已正确设置参数。它被用来生成使用24小时时间DropDownLists即SHH
的问题是在这里:
fName = CType(ctrl.FindControl("sHH"), DropDownList)
的嘘我需要相同的值FNAME。我曾尝试来连接:
fName = CType(ctrl.FindControl("'" & sHH & "'"), DropDownList)
这是我的错误,当我做以上:
操作“&”的类型“字符串”没有定义,并且“的System.Web.UI .WebControls.DropDownList”。
开始时间(07〜21) 开始分钟(00〜45)
结束时间(07〜21) 结束分钟(00〜45)
我不得不补充:
Private Property sHH As DropDownList
Private Property sMM As DropDownList
Private Property eHH As DropDownList
Private Property eMM As DropDownList
这里是我的声明:
'Populate arrays
Dim ddlHours() As Integer = {"07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"}
Dim ddlQuarter() As Integer = {"00", "15", "30", "45"}
popDDL(sHH, FormView1, ddlHours, 3)
popDDL(sMM, FormView1, ddlQuarter, 1)
popDDL(eHH, FormView1, ddlHours, 3)
popDDL(eMM, FormView1, ddlQuerter, 1)
这里是我的子程序:
Public Sub popDDL(ByVal fName As DropDownList, ByRef ctrl As Control, ByVal iDDL() As Integer, Optional ByVal OpLoopTo As Integer = 0)
'Find the control
fName = CType(ctrl.FindControl("sHH"), DropDownList)
'Loop through the length of iDDL items
For i As Integer = 0 To iDDL.Length - 1
'Loops through optional value so that I can add leading zeros if necessary
If OpLoopTo > -1 Then
Dim j As Integer = 0
If j < OpLoopTo Then
j += 1
'Add Leading zeros to the first values
fName.Items.Add(iDDL(i).ToString("D2"))
Else
'No leading for the remaining
fName.Items.Add(iDDL(i))
End If
Else
fName.Items.Add(iDDL(i))
End If
Next
End Sub
我只是一直在做.NET一个多星期,我不确定我是否已正确设置参数我。
任何想法
答
我的道歉,这并不困难。我走开,带着新鲜的眼睛回来。
我创建了一个名为fieldID一个额外的参数作为字符串
声明:
popDDL(sHH, "sHH", FormView1, ddlHours, 3)
功能参数和用法:
Public Sub popDDL(ByVal fName As DropDownList, ByRef fieldID As String, ByRef ctrl As Control, ByVal iDDL() As Integer, Optional ByVal OpLoopTo As Integer = 0)
'Find the control
fName = CType(ctrl.FindControl(fieldID), DropDownList)
对不起任何浪费的时间。
它很好,你工作了...有时这些东西闪现在你身上。你能把这个标记为你的答案吗? – Mych
我只能在恐惧的两天后将自己的答案标记为正确。 –
我不知道...显示我已经设法回答我自己的问题的次数。 – Mych