Click here to Skip to main content
15,881,882 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.
XML
<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 not getting how to solve this task.
please suggest me.
Posted
Updated 1-Jan-14 0:16am
v2

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
 
v3
Comments
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]

to
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
 
v3

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