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 / June 2007

Tip: Looking for answers? Try searching our database.

Add new row to binded Dropdownlist retrieved from database table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dungdang - 13 Jun 2007 14:34 GMT
Hello,

I want to add a new row on top of the list retrieved from a database
table..aparantely the it can retirne the list from a table but can't
add the new row as indicated below..what should I do? or is there any
other way to this rather.

dungdang,

=========================CODE START=================
              objConnection = new SqlConnection(strConnection);
    objConnection.Open();

               string strSelect = "SELECT staff_id, staff_l_name FROM
Faculty_Staff_Details";
               objCommand3 = new SqlCommand(strSelect,
objConnection);
    objDataReader3 = objCommand3.ExecuteReader();
    drpStaff.DataSource = objDataReader3;

    drpStaff.DataTextField = "staff_l_name";
    drpStaff.DataValueField = "staff_id";

    ListItem liItem = new ListItem("Vacant", "Vacant");
    drpStaff.Items.Insert(0, liItem);
    drpStaff.Items.Add(liItem);

    drpStaff.DataBind();
    objDataReader3.Close();
=====================CODE END=============================
Lloyd Sheen - 13 Jun 2007 14:56 GMT
> Hello,
>
[quoted text clipped - 26 lines]
> objDataReader3.Close();
> =====================CODE END=============================

There are two ways to fix your problem.

First and simplest is to change the order of your processing.  You are
adding the item and then binding.  The binding will clear all current data
(your "Vacant" item).  Add the new ListItem after you have databound.

OR

Change your SQL statement to add a UNION to add the extra row.

Hope this helps

Lloyd Sheen
dungdang - 13 Jun 2007 15:27 GMT
Thanks Lloyd, I've tried ur first suggestion and it solved my
problem..

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



©2008 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.