Results 1 to 4 of 4

Thread: How can i empty a drop down list in VB.Net

  1. #1
    Join Date
    Apr 2009
    Posts
    97

    How can i empty a drop down list in VB.Net

    From last few days i'm trying to empty the contents from a dropdown list, so that when a user click on the clear button, it should not display any data in VB.Net. I tried my level best for doing so, but couldn't succeed. So can any body tell me that how can i empty a drop down list in VB.Net? Does any body knows about it? Kindly provide me the correct solution for the above issue.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: How can i empty a drop down list in VB.Net

    If you want you can try out the following code:-

    Protected Sub DropDownList_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyControl1.DataBound, MyControl2.DataBound
    DirectCast(sender, DropDownList).Items.Insert(0, String.Empty)
    End Sub

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How can i empty a drop down list in VB.Net

    Try to make sure that your DropDownStyle property is been set to DropDown. Then you need to "Leave the Text" property blank and again you need to make sure that you don't change your SelectedIndex property to anything, but it should be set to -1.

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How can i empty a drop down list in VB.Net

    The following code will show you, how you can try to bind a DropDownList control along with data from a table on the DataBase.

    string s = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

    private void bindtoddl()
    {
    SqlConnection con = new SqlConnection(s);
    SqlCommand cmd = new SqlCommand("select FieldName from TableName", con);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    sda.Fill(ds);
    DropDownList1.DataSource = ds;
    DropDownList1.DataTextField = "FieldName"; // FieldName of Table in DataBase
    DropDownList1.DataValueField = "FieldName";
    DropDownList1.DataBind();

    }

Similar Threads

  1. Windows Explorer Drop Down Address Bar remains Empty
    By Lolla K. in forum Windows Software
    Replies: 7
    Last Post: 10-10-2011, 03:30 PM
  2. Drop down list of IE in Windows Phone 7
    By Chomu2 in forum Portable Devices
    Replies: 3
    Last Post: 27-10-2010, 07:52 AM
  3. How to add a Search Box to the drop down Tab list in Firefox?
    By abigial_i in forum Technology & Internet
    Replies: 5
    Last Post: 27-03-2010, 11:44 AM
  4. Populate a Drop down list in php from SQL
    By GunFighter in forum Software Development
    Replies: 2
    Last Post: 18-03-2009, 09:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,865,465.36476 seconds with 17 queries