Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I am new to this field so please help me out.


I want to display value from database table to asp.net controls lik textbox etc.... Using repeater i am displaying all values in controls .Now i want to display a value as selected value in dropdownlist . What to do?

Please help me guys......
Posted

1) Handle the DataBinding event

2) Dropdown list's Items collection has methods like FindByValue,FindByText methods. Using that you can get the ListItem from the dropdownlist.

3) Set the ListItem's Selected property to True
 
Share this answer
 
Comments
sajna m nair 24-Mar-11 1:40am    
Thankx for your reply.I understood wht you said but,can you please show me this with an example code.
sajna m nair 24-Mar-11 1:44am    
Actually this is a code for updating. so i want to display the existing value in the database and along with that the other option for changing data also
Albin Abel 24-Mar-11 2:34am    
Usually we won't provide coding, you need to try. May be I can give you a simple example coding. I am busy right now, will give you that by the end of the day
Hi,

try this

XML
<asp:Repeater ID="Rep" runat="server" OnItemDataBound="rep_ItemDataBound">
                               <ItemTemplate>
                                   <table width="100%">
                                       <tr>
                                           <td valign="top" width="13%" align="left">
                                               <asp:DropDownList ID="Dropdown1" runat="server" Width="80px">
                                               </asp:DropDownList>
                                       </tr>
                               </ItemTemplate>
                               <FooterTemplate>
                                   </table>
                               </FooterTemplate>
                           </asp:Repeater>


//in the code behind section

in the repDataBound Event find that drop down and bind it
               
                    DropDownList myDD = (DropDownList)e.Item.FindControl("Dropdown1");
                    myDD.DataTextField = "Name";
                    myDD.DataValueField = "Id";
                    myDD.DataBind();
 
Share this answer
 
v4

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