473,388 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Dropdown listbox and auto-postback problem

I have a dropdown listbox whose datasource is a dictionary.
When I have added items to the list and try to select an item from the list, the item I selected does not get the focus. And this comes when I changed the property autopostback to true.
Here are some of the codes which are relevant to it.
Expand|Select|Wrap|Line Numbers
  1.  
  2. protected void Page_Load(object sender, EventArgs e)
  3.         {
  4.             if (!IsPostBack)
  5.                 LoadList();
  6.         }
  7. private void LoadList()
  8.         {
  9.             cbxProduct.DataSource = Supplies;
  10.             if (!IsPostBack)
  11.             { 
  12.                 Supplies.Add("Banana", 1);
  13.                 Supplies.Add("Annana", 1);
  14.                 cbxProduct.DataTextField = "Key";
  15.                 cbxProduct.DataValueField = "Value";
  16.             }
  17.             cbxProduct.DataBind();
  18.  
  19.         }
  20.         public Dictionary<string, int> Supplies
  21.         {
  22.             get
  23.             {
  24.                 if (Page.Session["supplies"] == null)
  25.                 {
  26.                     Dictionary<string, int> supplies = new Dictionary<string, int>();
  27.                     Page.Session["supplies"] = supplies;
  28.  
  29.                 }
  30.                 return (Dictionary<string, int>)Page.Session["supplies"];
  31.             }
  32.             set
  33.             {
  34.                 Page.Session["supplies"] = value;
  35.             }
  36.  
  37.         }
  38.  
Oct 27 '10 #1
1 2498
Bassem
344 100+
Hi, shouldn't line #9 be moved under the if-statement on the top of the DataBind Method? Also, why you double check the IsPostBack.

I think when you set the property autopostback to true the ComboBox will be reset to have its original datasource, because of the post back.
Oct 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: James W. Hall Sr. | last post by:
I am filling a dropdown listbox in ASP.NET. The display value is a date field from SQL Server. When I bind the data to the dropdown listbox the time appears in with the data (12:00 am). In the...
2
by: Jason Sobell | last post by:
Hi, I'm trying to figure out a sensible way of making a combobox (configured as a dropdown list) behave in a read-only fashion. Setting Enabled=False will grey the text and the background, but I...
1
by: anand basha | last post by:
Hi, how to set array of values to the dropdown listbox while clicking the button *** Sent via Developersdex http://www.developersdex.com ***
3
by: anand basha | last post by:
Hi, How to set values dynamicaly to dropdown listbox while clicking the button *** Sent via Developersdex http://www.developersdex.com ***
2
by: Peanutt | last post by:
Hi! Could someone help me ? I've a ListBox with 3 items. How do i select automaticly the 1st, 2nd or 3rd ? ( whithout clicking in it ? ) Thank you!
4
by: fat | last post by:
I have a drop down combo box that displays a list of customers , and the list is growing.. I would like to click the dropdown arrow and have a List box in a new form open, then i can choose a...
1
by: Ted | last post by:
Here is a stored procedure I created in MySQL: CREATE PROCEDURE `sp_find_food`( IN search_string varchar(255) ) BEGIN DECLARE ss VARCHAR(257); SET ss = CONCAT('%',search_string,'%'); SELECT...
2
by: salo | last post by:
hi im designing a employee project in that empid should be get displayed in dropdown listbox ...it should take values from the database...its C# coding.... and also if a click that empid...all the...
6
by: Amirtha | last post by:
hi frnds, I need ur help .im new to the javascript. i want to drag and drop an item from one dropdown listbox to an another dropdown listbox.i dont know how to do this. if possible means plz help...
1
by: OldBirdman | last post by:
I have a subroutine to dropdown the list portion of a ComboBox. Private Sub QuickShow() 'Display Quick Dropdown ListBox cboQuick = cboQuick.DefaultValue cboQuick.SetFocus ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.