如何根据sql表值绑定下拉? [英] how to bind drop down according to sql table values?
问题描述
我只想绑定dropdownlist,它在gridview控件中被绑定为项目模板。我想绑定下拉列表与sql表中特定列的不同值。我尝试过如下,但每次下拉播种相同的值,但我想相应地显示表值。我想通过更改下拉列表值来更新这些值。
i just want to bind dropdownlist which is bounded as a item templete in gridview control. i want to bind dropdown with distinct values of particular column in sql table. i have tried like below but every drop down sowing same value but i want to show table values accordingly. and i want to update that values by changing dropdownlist values.
<asp:TemplateField HeaderText="implementd_remarks" SortExpression="implementd_remarks">
<EditItemTemplate>
<asp:TextBox ID="TextBox21" runat="server" Text='<%# Bind("implementd_remarks") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="implementd_remarks" DataValueField="implementd_remarks">
<asp:ListItem Value="%">...SELECT...</asp:ListItem></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TX_MediaConnectionString %>" SelectCommand="SELECT DISTINCT [implementd remarks] AS implementd_remarks FROM [lbs]"></asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
i am没有得到怎么样完成这项任务。
请建议我。
i am not getting how to solve this task.
please suggest me.
推荐答案
ConnectionStrings:TX_MediaConnectionString %> SelectCommand = < span class =code-keyword> SELECT DISTINCT [implementsd remarks] AS implementd_remarks FROM [lbs] > < / asp:SqlDataSource >
< / ItemTemplate >
< / asp:TemplateField >
ConnectionStrings:TX_MediaConnectionString %>" SelectCommand="SELECT DISTINCT [implementd remarks] AS implementd_remarks FROM [lbs]"></asp:SqlDataSource> </ItemTemplate> </asp:TemplateField>
i我没有得到如何解决这个任务。
请建议我。
i am not getting how to solve this task.
please suggest me.
您应该在后面的代码中实现查询,以便分离数据和表示层。看看这个: binding-data-to-dropdownlist-from-sql-table?forum = csharpgeneral [ ^ ]
You should implement the query at the code behind so as to separate data and presentation layers . Check this out: binding-data-to-dropdownlist-from-sql-table?forum=csharpgeneral[^]
Alias似乎错位了。尝试更改用于填充不同值的选择查询
Alias seems to be misplaced. Try to change select query used to fill distinct values
SELECT DISTINCT [implementd remarks] AS implementd_remarks FROM [lbs]
to
to
SELECT DISTINCT [implementd_remarks ] AS implementd remarks FROM [lbs]
如果要进行多列选择,则在列之间使用逗号分隔
If multiple column selection was intended then use comma separation between the columns
这篇关于如何根据sql表值绑定下拉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!