Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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!
Posted 16-Jan-13 22:27pm
Edited 19-Jan-13 2:48am
v3
Comments
ram_kumar at 17-Jan-13 3:31am
   
hey can u post your code then we will do better for you. otherwise you can dynamic add height on selectedchangeindex its maintain your height.
Mohd. Mukhtar at 17-Jan-13 3:35am
   
What have you tried so for? Please copy some code snippet here.
vinodkumarnie at 17-Jan-13 4:55am
   
It seems easy to resolve if you Post your code. So please post code.
S.Rajendran from Coimbatore at 17-Jan-13 4:56am
   
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.
richcb at 17-Jan-13 16:04pm
   
You need to use the "Improve Question" widget to add the code to your thread.
S.Rajendran from Coimbatore at 19-Jan-13 7:47am
   
The problem happens only when I use VS 2008 R2. In VS2008 no problem. Today I found it.
S.Rajendran from Coimbatore at 19-Jan-13 21:42pm
   
Well, there is a correction. It is not VS 2008 R2..it is VS2008 team system.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please try this..
<script src="jquery-1.4.2.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('#btnRight').click(function(e) {
        var selectedOpts = $('#lstBox1 option:selected');
        if (selectedOpts.length == 0) {
            alert("Nothing to move.");
            e.preventDefault();
        }
 
        $('#lstBox2').append($(selectedOpts).clone());
        $(selectedOpts).remove();
        e.preventDefault();
    });
 
    $('#btnLeft').click(function(e) {
        var selectedOpts = $('#lstBox2 option:selected');
        if (selectedOpts.length == 0) {
            alert("Nothing to move.");
            e.preventDefault();
        }
 
        $('#lstBox1').append($(selectedOpts).clone());
        $(selectedOpts).remove();
        e.preventDefault();
    });
});
    </script>
<table style='width: 370px;'>
            <tr>
                <td style='width: 160px;'>
                    <b>Group 1:</b><br />
                    <select multiple="multiple" id='lstBox1'>
                        <option value="ajax">Ajax</option>
                        <option value="jquery">jQuery</option>
                        <option value="javascript">JavaScript</option>
                        <option value="mootool">MooTools</option>
                        <option value="prototype">Prototype</option>
                        <option value="dojo">Dojo</option>
                    </select>
                </td>
                <td style='width: 50px; text-align: center; vertical-align: middle;'>
                    <input type='button' id='btnRight' value='  >  ' />
                    <br />
                    <input type='button' id='btnLeft' value='  <  ' />
                </td>
                <td style='width: 160px;'>
                    <b>Group 2: </b>
                    <br />
                    <select multiple="multiple" id='lstBox2'>
                        <option value="asp">ASP.NET</option>
                        <option value="c#">C#</option>
                        <option value="vb">VB.NET</option>
                        <option value="java">Java</option>
                        <option value="php">PHP</option>
                        <option value="python">Python</option>
                    </select>
                </td>
            </tr>
        </table>
 
Hope it work well...
 
Thank you..
  Permalink  
Comments
Marcus Kramer at 11-Feb-13 17:13pm
   
Plagiariazed from: Source.
When you copy and paste a solution from another source, you must provide a link to that source. As this is the first time, I'm not going to downvote your report the answer, but rather just let you know what's expected. Cheers.
vinodkumarnie at 11-Feb-13 23:06pm
   
sure

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 425
1 OriginalGriff 184
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 163
0 OriginalGriff 7,854
1 DamithSL 5,949
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,084
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 19 Jan 2013
Copyright © CodeProject, 1999-2014
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