找不到嵌套数据源
我有一个数据源需要收集标签信息。它们都位于连接到不同数据源的 DataList 内部。当我调试应用程序时,该值是 Nothing。我以为我的措辞是正确的,因为没有波浪线,但它不起作用。有人可以帮我找到数据源以便我完成这个项目吗?
我尝试了 FindControl("dsPicklist")
和 DirectCast(FindControl("dsPicklist"), SqlDataSource)
但都没有返回值。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Find the nested DataSource control in the DataList.
Dim ds As SqlDataSource = DirectCast(FindControl("dsPicklist"), SqlDataSource)
'convert the DataSource into a dataView
Dim dv As DataView = DirectCast(ds.[Select](DataSourceSelectArguments.Empty), DataView)
For Each drv As DataRowView In dv
'Find the label
Dim lbl As Label = FindControl("Label3")
'Display the data into the label
lbl.Text = dv("TEXT").ToString
Next
End Sub
<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>
I have a datasource that needs to gather information for a label. These are both inside of a DataList that is connected to a different DataSource. When I debug my application, the value is Nothing. I thought I had the verbage right since there are no squiggly lines, but it isn't working. Can someone help me find the datasource so I can get this project done?
I tried FindControl("dsPicklist")
and DirectCast(FindControl("dsPicklist"), SqlDataSource)
but neither one gets a value returned.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Find the nested DataSource control in the DataList.
Dim ds As SqlDataSource = DirectCast(FindControl("dsPicklist"), SqlDataSource)
'convert the DataSource into a dataView
Dim dv As DataView = DirectCast(ds.[Select](DataSourceSelectArguments.Empty), DataView)
For Each drv As DataRowView In dv
'Find the label
Dim lbl As Label = FindControl("Label3")
'Display the data into the label
lbl.Text = dv("TEXT").ToString
Next
End Sub
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我不知道为什么
DataList
中有SqlDataSource
,但代码中有一些错误。您应该将
添加到标记中。在您的代码中,您可以在
DataList1.Items
内找到SqlDataSource
控件Although I dont know why you have the
SqlDataSource
inside theDataList
, you have some error in the code. You should add<ItemTemplate>
to your markup.And in your code you find the
SqlDataSource
control inside theDataList1.Items