Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to add the select item in dropdownlist zero'th element when i dound with that dropwnlist with the database
how it can be possible
Posted

Hi,

try with this,


ASP.NET
<asp:dropdownlist id="DropDownList1" runat="server" width="200px" xmlns:asp="#unknown">
            AppendDataBoundItems="true" DataSourceID="sdsdropdown" DataTextField="Name" 
             DataValueField="Id">
         </asp:dropdownlist>



ASP.NET
<asp:SqlDataSource ID="sdsdropdown" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ConnectionStringname %>" 
                            SelectCommand="SELECT [Id], [Name] FROM [table]">
                        </asp:SqlDataSource>






or

ASP.NET
<asp:dropdownlist id="DropDownList1" runat="server" width="200px" xmlns:asp="#unknown">
              DataSourceID="sdsdropdown" DataTextField="Name" 
             DataValueField="Id">
         </asp:dropdownlist>



<asp:sqldatasource id="sdsdropdown" runat="server" connectionstring="<%$ ConnectionStrings:ConnectionStringname %>" xmlns:asp="#unknown">
                                                SelectCommand="SELECT 0 as [Id] ,'--Select--' as  [Name] union SELECT [Id], [Name] FROM [table]">
                                            </asp:sqldatasource>
 
Share this answer
 
hello Reshma,

just try this after binding the dropdownlist with database.

C#
ddl.Items.Insert(0, new ListItem("-Select-", "0"));


Hope this will help you.
And don't forget to mark as answer if it helps. :)
 
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