Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am fresher in asp.net.
i have a dropdownlist in grid with list items in it.

i cant bind the values from database in itemtemplate while using Gridview.Databind()

here is my dropdownlist
<pre lang="HTML">
<asp:DropDownList ID="DropDownList3"   runat="server" Height="16px" Width="53px" SelectedValue='<%# Bind("EdnLevel") %>' >
<asp:ListItem Selected="True">Nos</asp:ListItem>
<asp:ListItem>Kg</asp:ListItem>
<asp:ListItem>Ltr</asp:ListItem>

</asp:DropDownList>
Posted
Comments
nandakishoreroyal 14-Jun-13 5:27am    
If You want to bind drop down from data base then you should remove the list items....


bring records in to datatable and bind it to dropdown list...
Shafeequl 14-Jun-13 5:58am    
i think when you bind from db..the list item vl gone..bcos the dropdown list is filled with the new items from the db

ASP.NET
<asp:dropdownlist id="DropDownList3" runat="server" height="16px" width="53px" selectedvalue="<%# Bind("EdnLevel") %>" xmlns:asp="#unknown">
<asp:listitem>Nos</asp:listitem>
<asp:listitem>Kg</asp:listitem>
<asp:listitem>Ltr</asp:listitem>
 
</asp:dropdownlist>

and now you have to find the dropdownlist within grid
on rowdatabound event
eg.

dropdownlist objddl=(dropdownlist)grid1.rows[rowindex].fincontrol["dropdownlist id"];
objddl.SelectedValue="Assiged The Data What U Want"
 
Share this answer
 
Comments
musnaas 14-Jun-13 5:55am    
thank you ..problem solved
You can visit the following link which is pretty much self explanatory...

hope that will help... :)



http://stackoverflow.com/questions/7227510/asp-net-right-way-to-populate-a-dropdown-list-from-database[^]
 
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