如何使用 SqlDataSource 填充组合框以及数据表或数据集
当从更改事件的下拉列表中选择某个值时,我试图从数据源获取列值。
<asp:DropDownList ID="ddlCityName" runat="server" DataSourceID="dsCity"
DataTextField="CityName" DataValueField="CityID" AutoPostBack="True"
OnTextChanged="CityName_OnTextChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="dsCity" runat="server"
ConnectionString="<%$ ConnectionStrings:GmapConnectionString %>"
SelectCommand="SELECT * FROM [vcity]"></asp:SqlDataSource>
在这里,我想从 sqldatasource 获取未绑定到 ddlCityName 的任何其他列的值。
我在数据源中有四列,即名称、ID、地址、电话号码。
我想获取从 ddl 中选择某些值的人的地址。
I am trying to fetch a column value from a datasource when some value is selected from a dropdownlist on its change event.
<asp:DropDownList ID="ddlCityName" runat="server" DataSourceID="dsCity"
DataTextField="CityName" DataValueField="CityID" AutoPostBack="True"
OnTextChanged="CityName_OnTextChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="dsCity" runat="server"
ConnectionString="<%$ ConnectionStrings:GmapConnectionString %>"
SelectCommand="SELECT * FROM [vcity]"></asp:SqlDataSource>
Here I want to fetch any other column's value that is not binded to a ddlCityName from sqldatasource.
I have four columns in datasource i.e. name, id, address, phno.
I want to fetch an address of a person who selects some value from ddl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
我不知道具体如何做到这一点,但在这种情况下我使用的是这样的,我将我的值组合在一起并将它们全部添加到 DDList 的值字段中,例如您想要 ID 和地址,所以将它们添加为这在您的选择查询中:
选择 Cast(id as varchar) + '##' + 地址 ....
您可以使用您认为唯一的任何分隔符,然后只需拆分值字符串即可。
I don't know exactly how you can do that, but what I use in this situation is this, I combine my values together and add them all to the value field of DDList, for example you want ID and Address, so add them like this in your select query :
select Cast(id as varchar) + '##' + address ....
you can use any separator that you think will be unique, then just simply split the value string.