Click here to Skip to main content
11,483,003 members (72,695 online)

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.


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

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.
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 | Mobile
Web04 | 2.8.150520.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
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