transfering a single row value to the dropdown list

Posted by Anoo under ASP.NET on 9/2/2009 | Views : 1006 | Status : [Member] | Replies : 1
i had a problem while am transfering one table row values(like sno of student table) to the list of dropdown list.i used DataReader.

please send me the solution.

thanking you


Posted by: Vuyiswamb on: 9/2/2009 [Member] [MVP] [Administrator] NotApplicable

Good Morning Anoo

i have looked at your Code, and i presume you want to display a certain Field in your Dropdownlist.

First you write your SQl like this

select * from clg

This is not nice , you have to select a Column that you want to Display in your DropDownlist like this e.g

select [sno] from clg

I see you used a Reader, its Cool , but i would prefare that you use a Datable unless you see the perfomance issue that i think will not happen unless you are doing strange things in your code.

Now when you Bind a dropdownlist. You have to tell the Dropdownlist that you want to display a certain Field, remember a dropdownlist is not like a gridview , so you have to specify the Field. Using the DataTextField Property you can give the name of the Field to be displayed. Remember one thing my friend, there moment you have a Select * in your SQL , always remember that , it is not a good Programming practice to do that.

Thank you For Posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda

Anoo, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response