如何正确设置DataSourceID属性? [英] How do I properly set the DataSourceID property?

查看:765
本文介绍了如何正确设置DataSourceID属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计方面,我有这个:



< asp:DropdownList ID =ddlSystemSubTypeSearch runat =serverDataSourceID =sdsSystemSubTypesDataTextField =stSystemSubTypeDataValueField =sstSTIDWidth =250px>< / asp:DropdownList> 





在背后的代码上,我有这个:



 如果修剪(Request.QueryString(  SystemSubType))<> 字符串 .Empty 然后 
.ddlSystemSubTypeSearch.DataBind()
Me .ddlSystemSubTypeSearch.SelectedValue = Request.QueryString( SystemSubType)。修剪
结束 如果







 私有  Sub  ddlSystemSubTypeSearch_DataBound( ByVal  sender 正如 对象 ByVal  e  As  System.EventArgs)句柄 ddlSystemSubTypeSearch.DataBound 
.dd lSystemSubTypeSearch.Items.Insert( 0 ListItem( , - 1))
结束







当我运行程序时,我得到了这个错误:



Quote:

'ddlSystemSubTypeSearch的DataSourceID '必须是IDataSource类型的控件的ID。无法找到ID为sdsSystemSubTypes的控件。





似乎我无法弄清楚代码有什么问题。

任何帮助都将不胜感激。

解决方案

错误告诉你它是搜索ID sdsSystemSubTypes 的控件。如果你还没有声明任何这样的 DataSource 控件,比如 SqlDataSource 或其他什么东西,那么它就会抛弃你。



参考 - BaseDataBoundControl.DataSourceID属性 [ ^ ]举个例子。


我声明控件是这样的:



 <   asp:SqlDataSource     ID   =  sdsSystemSubTypes    runat   =  server  

ConnectionString = <%


ConnectionStrings:ClassicAutomation %>

< span class =code-attribute> ProviderName = <%

On the design side, I have this:

<asp:DropdownList ID="ddlSystemSubTypeSearch" runat="server" DataSourceID="sdsSystemSubTypes" DataTextField="stSystemSubType" DataValueField="sstSTID" Width="250px"></asp:DropdownList>



And on the code behind side, I have this:

If Trim(Request.QueryString("SystemSubType")) <> String.Empty Then
                  Me.ddlSystemSubTypeSearch.DataBind()
                  Me.ddlSystemSubTypeSearch.SelectedValue = Request.QueryString("SystemSubType").Trim
              End If




Private Sub ddlSystemSubTypeSearch_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSystemSubTypeSearch.DataBound
       Me.ddlSystemSubTypeSearch.Items.Insert(0, New ListItem("", -1))
   End Sub




When I run the program, I get this error:

Quote:

The DataSourceID of 'ddlSystemSubTypeSearch' must be the ID of a control of type IDataSource. A control with ID 'sdsSystemSubTypes' could not be found.



Seems I can't figure out what is wrong with the code.
Any help will be greatly appreciated.

解决方案

The error is telling you that it is searching for a Control with ID sdsSystemSubTypes. If you have not declared any of such DataSource control like SqlDataSource or something, then it would throw you this.

Refer - BaseDataBoundControl.DataSourceID Property[^] for one example.


I declared the control like this:

<asp:SqlDataSource ID="sdsSystemSubTypes" runat="server"

          ConnectionString="<%


ConnectionStrings:ClassicAutomation %>" ProviderName="<%


这篇关于如何正确设置DataSourceID属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆