Хотя я не знаю, почему у вас SqlDataSource
внутри DataList
, в коде есть ошибка.Вы должны добавить <ItemTemplate>
к вашей разметке.
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
Width="100%" CellPadding="4" ForeColor="#333333">
<ItemTemplate>
<asp:HiddenField ID="hiddenPicklistID" runat="server"
Value='<%# Bind("PicklistID") %>' />
<asp:Label ID="Label3" runat="server"></asp:Label>
<asp:SqlDataSource ID="dsPicklist" runat="server"
ConnectionString="<%$ ConnectionStrings:SurveyConnectionString %>"
SelectCommand="SELECT p.TEXT FROM PICKLIST p
JOIN C_Survey_Questions c
ON p.PICKLISTID = c.PicklistID
AND c.QuestionID = @QuestionID
AND c.SurveyID = @SurveyID
WHERE p.PICKLISTID IS NOT NULL
AND c.PicklistID IS NOT NULL">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="SurveyID"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="HiddenField2" Name="QuestionID"
PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:DataList>
И в вашем коде вы найдете элемент управления SqlDataSource
внутри DataList1.Items
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Make sure DataList1 is databound before doing this
For Each item As DataListItem In DataList1.Items
Dim lbl As Label = DirectCast(item.FindControl("Label3"), Label)
Dim ds As SqlDataSource = DirectCast(item.FindControl("dsPicklist"), SqlDataSource)
Next
End Sub