Click here to Skip to main content
15,894,460 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.
Regards.


C#
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
	if (ListBox1.SelectedIndex == 0) 
	{ 
	
	} 
	else 
	{ 
		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(); 
			adds1.Add(ds1.Tables[0].Rows[i].ItemArray[0].ToString()); 
			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

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



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 http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900