Select item from DropDownList ...

Posted by Ramu02 under Regular Expressions on 3/6/2011 | Points: 10 | Views : 2574 | Status : [Member] | Replies : 5
In web page load i bind some data into dropdownlist (In delete section)..in the delete procedure i selected on item in list and click on delete button...In this process i got error like ..if i select 3rd item ..but the first item of the database is deleted.....can give me correct code for this .....i use dropdownlist1.Text. ...




Responses

Posted by: Gsolvers on: 3/6/2011 [Member] Starter | Points: 25

Up
0
Down
dropbox1.Text=value
listBox1.SelectedItems.Clear();

the "value" is text you want to delete in your case you can retrieve it using dropbox1.selecteditemtext

Best Regards,

VG
www.TeacherJi.com

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

Posted by: Ramu02 on: 3/6/2011 [Member] Starter | Points: 25

Up
0
Down
actually i bind the data from database.....i cant get what i want...

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

Posted by: Gsolvers on: 3/6/2011 [Member] Starter | Points: 25

Up
0
Down
This is fine. But after binding you are selecting the value from drop down box right? If yes, the above code should work fine.

Best Regards,

VG
www.TeacherJi.com

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

Posted by: Karthikanbarasan on: 3/6/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Your requirement should be like, once u select the value in the drop down or list box and click on button delete then it should delete the value in the database?

If this is the case then your code should be some thing like below

in the selected event trigger of the drop down or list box get the value in a string and you need to connect to the database and delete that record. If Selected value is not working in the drop down list then go with the SELECTED INDEX.

Thanks
Karthik
www.f5Debug.net

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

Posted by: Madhu.b.rokkam on: 3/6/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Make sure you have set the enable view state property to true, and also make sure your are not binding date to the dropdown on post back, usually developers tend to forget and bind data to dropdown even on post back, this tends to change the selected item to the default first item so that in your case too so that is getting deleted.

Thanks and Regards
Madhu

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

Login to post response