Click here to Skip to main content
13,505,586 members

on listbox selected index changed problem

S.Rajendran from Coimbatore asked:

Open original thread
In my project I bind a listbox1 with say 60px height. When I select an item (for raising another listbox2, using the selected item) that is beneath the 60px height using vertical scroll bar, the status of the listbox is returning back to the first position thereby the selected item goes unknown for the user. Is there any facility to retain the status of listbox on that selected item itself.

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) 
	if (ListBox1.SelectedIndex == 0) 
		SqlDataAdapter da1 = new SqlDataAdapter("select block_name,block_code from block where dist_code='" + v_dist_code + "'", con); 
		SqlCommandBuilder cb1 = new SqlCommandBuilder(da1); 
		DataSet ds1 = new DataSet("block"); 
		da1.Fill(ds1, "block"); 
		for (int i = 0; i < ds1.Tables[0].Rows.Count; i++) 
			List adds1 = new List(); 
			string name1 = ds1.Tables[0].Rows[i]["block_name"].ToString(); 
			if (name1 == ListBox1.SelectedValue) 
				v_block_code = Convert.ToInt32(ds1.Tables[0].Rows[i]["block_code"].ToString()); 
// once an item is selected the position of listbox goes to top and things happens as reported.

[EDIT]David_Wimbley: Moved code from comment to question[/EDIT]

// This problem only with VS2008 R2 and not with VS2008!
Tags: C#, ASP.NET


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web01 | 2.8.180417.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100