如何使用 SqlDataSource 填充组合框以及数据表或数据集

发布于 2024-08-30 11:13:34 字数 610 浏览 1 评论 0原文

当从更改事件的下拉列表中选择某个值时,我试图从数据源获取列值。

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-09-06 11:13:34

我不知道具体如何做到这一点,但在这种情况下我使用的是这样的,我将我的值组合在一起并将它们全部添加到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文