Binding Data Source To DropDownList in ASP.NET

Manzoor Ahmed
A free video tutorial from Manzoor Ahmed
Microsoft Certified Trainer
4.3 instructor rating • 11 courses • 112,364 students

Learn more from the full course

The Complete ASP.Net Web Forms with ADO.Net From Scratch

Rapid Web Application Development Using Asp.Net

09:33:46 of on-demand video • Updated November 2015

  • Creating a project and running in web browser
  • Working with standard controls
  • Working with Data controls
  • Working with validation controls
  • Working with Master pages
  • Working with Navigation controls
  • Working with Login controls
  • Understanding session management technique.
  • Understanding web.config file and machine.config
  • Working with client side reports
  • Working with Datareader in Ado.Net
  • Working with Dataset in Ado.Net
English [Auto] Hello I'm one going to show you how to work with the group don't just by binding it to the database say I have a dropdown list I'll drag and drop it. You know what I need to be do we have seen how to add items to the list many who really know what they want is I want the items in the dropdown list to be blind to the database. I want the values to get from the database to how do I do that. It's very simple. I need to go to my skill set. Express a vision. I have a database called an organization and the tables in IT employee table. And I was just like go on this and would say at the top 200 rows to see me what all the columns and the values that I have in them like they have now I want to display employee name in the drop down list and the salary should be the value of that. So whenever I I have dropped on this we have seen we have two properties when it's like selected item and that is when the second item should be avoided and selected a value should be selected. So if we want to do that I need to connect my project to do it. So how do they connect that new coffee the server name and I'll go to my region over there. And I would just say you did a lot of this is the new window that we are looking in to for the first time. That is one thing about database Explorer. Now this is my database Explorer and I can add connections said just add connection connect with it or is it will ask me to want it because we want to connect. I want to connect with skill so what it is I'll say connect. And the name I'll paste it here and test whether it is working fine. Yeah it's working fine now I'll select the database. That is nothing but Organization. OK. So I should get that database here in my database Explorer. No I have the database ready with me. I can work with this database as I like. Now come back to all of you on list. This is how we got connected to that database. Now I want to connect to this particular table. So how do I do that. So I get robbed on this. Click on the smart that idea. We click on it item. Now this time I'll be clicking on Tuesday or source now from your house select Edit. This time I want to select a new record source that is nothing but a database. Now I will say OK it is going to show me the database name in the the list. So there is nothing but organization selected out and next. It says that see if the connection is linked to the application configuration file. I'll say OK save it with that name. My organization can't find a string. That means from the next one word whenever I want to connect to the database in future. In my project it is not going to ask me to select the database again. It will simply say connect with this connection of string. I can simply proceed with that connection string. Name the name of the condition for my own when I can it from history I'll say next here I have got them like they and I'll say select employee ID US-Saudi select employee name and employee cell. Why because I want to make item as a name and value as salary. I say next that's the Kuwaiti it will display the name and the salary and finish. But this time I should say the display field or bit of fields should be employee name and the value field should be salary that the item should be name and the value should be set. OK that's it. I like that you do this to display me all them boys. Jack Peterlee month. So this is fine but the first item should we select by default. So how do I get that value. It is very simple. Click on the items and you add the selected and let the value be zero and see OK. And save this is this enough. When I had select is it going to reflect in the dropdown list. No it is not going to reflect and debate on don't ask why because I need to set one property of the world on this. That is nothing but a Band-Aid on items to prove. Whenever I said this property a predicate I want items to prove what is protected. If we do it will display select and it isn't going to happen. What I what I get from that the debates now here I got to select in the dropdown list now the last thing that I want to do here is whenever I click on a button what did the teacher say hello Mr. the name of the employee and said Hello Mr. at your salary. And so I want to dispel that. So it is very simple. I can click on the button and I can simply figure out a string else is playing. K equals to. And here I would say get less equals to drop down list one dot selected item then bingo big the name dot with string is going to be that is then I'll say OK plus equals 2. That means it will say hello. Then the name of them might then some space. Plus I will say some spell. Then I write you are salary is this then I get I'll say OK let's equals to drop down list 1 door selected value got to think so I'm just playing Hello than that man then some spare salary is this space then it's value. Know I want to write this to that window so I'll simply say irresponsive don't write as Phyfe. So this is going to work perfectly whenever I select an employee and click the button to give me the salary of that particular employee. Haloperidol your salary is called Hello Jack your salary is fifty call them. Hello Mark. Your salary sounds like select. If I don't start anything and if I say big button Hello select your cell it is zero. Actually you should by the date it should say that you need to select any one item before clicking on the button before submitting the form. So distinctly with the letting you know if you will that is nothing but get it is in control. So this is how I can bind drubbed on this to that database. Thank you very much.