Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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">
                        <asp:TextBox ID="TextBox21" runat="server" Text='<%# Bind("implementd_remarks") %>'></asp:TextBox>
                        <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>

i am not getting how to solve this task.
please suggest me.
Updated 1-Jan-14 0:16am

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[^]
Share this answer
sudhakar19 1-Jan-14 7:17am    
string stri = ((DropDownList)GridView1.Rows[i].Cells[21].FindControl("implementd_remarks")).SelectedValue;
i hav tried like this and it is working but always stri getting null value.
is there any other way to get value of dropdownlist in a string.
JoCodes 1-Jan-14 7:49am    
Whats [implementd remarks] here column name or was intending a 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]

SELECT DISTINCT [implementd_remarks ] AS implementd remarks FROM [lbs]

If multiple column selection was intended then use comma separation between the columns
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900