| | |
Trouble retrieving value from drop down list
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 38
Reputation:
Solved Threads: 0
I have a drop down list on my my aspx page. This box is populated from my sqlserver db. I want to allow people to search based on the value they select from the drop down list. The problem I am encountering is that it always returns the value of the first item in my list box. I am guessing my problem spurs from my lack of knowledge of postback, please help me.
This is the code im trying to use to retrieve the value of the ddl and use it as a parameter for another method.
In reality I simply need a way to store the value of the currently selected item in a variable for future use.
This is the code im trying to use to retrieve the value of the ddl and use it as a parameter for another method.
C# Syntax (Toggle Plain Text)
protected void btnTypeSearch_Click(object sender, EventArgs e) { photoPanel.Controls.Clear(); string type = ddType.SelectedItem.Text; DataLayer typeLayer = new DataLayer(); DataTable dt = typeLayer.fillTbl("SELECT * FROM Trees WHERE Type='" + type + "'"); fillGallery(dt); }
In reality I simply need a way to store the value of the currently selected item in a variable for future use.
Dear,
If you are loading DropDownList in Page_Load event then the code of databinding must be execute once.
IsPostBack property of Page class is used to determine whether a page is loaded first time or not.
You may add your databind code like this:
If you are loading DropDownList in Page_Load event then the code of databinding must be execute once.
IsPostBack property of Page class is used to determine whether a page is loaded first time or not.
You may add your databind code like this:
C# Syntax (Toggle Plain Text)
if(IsPostBack==false) { .. .. Place your databind code here.. }
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Other Threads in the C# Forum
- Previous Thread: please help me understand my linked list query!
- Next Thread: Saving Images into the database
| Thread Tools | Search this Thread |
.net access algorithm array asp barchart bitmap box broadcast c# check checkbox client column combobox control conversion csharp custom database datagrid datagridview datagridviewcheckbox dataset datetime degrees development display draganddrop drawing encryption enum event excel file form format formatting formbox forms formupdate function gdi+ httpwebrequest image index input install java label linux list listbox mandelbrot math mouseclick mysql namevaluepairs networking operator packaging parse path photoshop picturebox pixelinversion post programming radians regex remote remoting reporting richtextbox robot server sleep socket sql statistics stream string table text textbox thread time timer transform treeview update usercontrol validation visualstudio webbrowser wfa windows winforms wpf xml






