Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

Dropdownlist add default blank while bind to sql server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
syncwa - 14 Feb 2006 10:31 GMT
Hi,

My dropdownlist is binded to a sql datasource.
I would like to have it list a blank entry on top and do not show real
data before user select it.
How can I do this.? Thanks
Alejandro Penate-Diaz - 14 Feb 2006 11:07 GMT
after you databind do this:
this.DropDownList1.Items.Insert(0,"");

> Hi,
>
> My dropdownlist is binded to a sql datasource.
> I would like to have it list a blank entry on top and do not show real
> data before user select it.
> How can I do this.? Thanks
syncwa - 14 Feb 2006 14:28 GMT
Sorry, I'm new to this. I put it in test.aspx.cs but it doesn't work.
Could you take a look at the following code to see where I should put
this? Regards

test.aspx.cs::

public partial class test : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
       DropDownList1.Items.Insert(0, "");
   }
}

test.aspx:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="testSqlDataSource1"
           DataTextField="Company_Name" DataValueField="Company_ID">
       </asp:DropDownList><asp:SqlDataSource ID="testSqlDataSource1"
runat="server" ConnectionString="<%$
ConnectionStrings:kConnectionString %>"
           SelectCommand="SELECT [Company_Name], [Company_ID] FROM
[Companies]"></asp:SqlDataSource>
   
   </div>
   </form>
</body>
</html>

>after you databind do this:
>this.DropDownList1.Items.Insert(0,"");
[quoted text clipped - 5 lines]
>> data before user select it.
>> How can I do this.? Thanks
Alex D. - 14 Feb 2006 15:14 GMT
I would suggest to databind programatically instead of using the IDE.
otherwise I jus dont know  how to do it ;-)

> Sorry, I'm new to this. I put it in test.aspx.cs but it doesn't work.
> Could you take a look at the following code to see where I should put
[quoted text clipped - 42 lines]
>>> data before user select it.
>>> How can I do this.? Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.