我有2个DataLists,其中一个嵌套在另一个中。我有一行(Dim QID ....)不断给我带来问题,无论我在网上找到什么样的代码组合。我只是想让隐藏字段显示为一个整数,以便我的If语句可以工作。
Dim dl2 As DataList = CType(e.Item.FindControl("DataList2"), DataList)
Dim QID As Integer = Convert.ToInt32(e.Item.FindControl("HiddenField2"))
If QID = 33 Then
Dim lbl As Label = dl2.FindControl("Label3")
For Each i As ListItem In dl2.Items
If lbl.Text = "Self Directed" Or lbl.Text = "Systems" Then
lbl.Visible = False
End If
Next
End If
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
Width="100%" CellPadding="4" ForeColor="#333333">
<ItemTemplate>
<asp:HiddenField ID="HiddenField2" runat="server"
Value='<%# Eval("QuestionID") %>'></asp:HiddenField>
<asp:Label ID="lblQuesNum" runat="server" Font-Bold="True"
Text='<%# Eval("QuestionNum") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Font-Bold="True"
Text='<%# Eval("Question") %>'></asp:Label>
<asp:HiddenField ID="hiddenPicklistID" runat="server"
Value='<%# Eval("PicklistID") %>' />
<asp:HiddenField ID="HiddenField1" runat="server"
Value='<%# Eval("AnswerType") %>' />
<asp:DataList ID="DataList2" runat="server" DataSourceID="dsPicklist">
<ItemTemplate>
<asp:HiddenField ID="hidPickID" runat="server" value='<%# Eval("PICKLISTID") %>' />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("TEXT") %>'></asp:Label>
<asp:HiddenField ID="HiddenField1" runat="server"
Value='<%# Eval("AnswerType") %>' />
</ItemTemplate>
</asp:DataList>
</asp:TextBox>
答案 0 :(得分:1)
您无法将控件转换为数值。实际上,您希望将Hiddenfield
的值转换为整数。
Dim hidden2 = DirectCast(e.Item.FindControl("HiddenField2"), HiddenField)
Dim QID As Integer = Int32.Parse(hidden2.Value)