Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a listbox control which is binded to sqlDataSource dynamically.
I want to automatically adjust the size of listbox based on the items so that I do not get scroll bar.


I have tried using following code:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            Session["inv_Id"] = 55;
            int invId =Convert.ToInt32( Session["inv_Id"]);

            DataTable dt = new DataTable();
            dt=con.select_GroupCompany(invId);
            ASPxListBox1.ValueField = "GroupId";
            ASPxListBox1.TextField = "GroupName";
            ASPxListBox1.DataSource = dt;
            ASPxListBox1.DataBind();
            int rowCount = dt.Rows.Count;
            ASPxListBox1.Rows = rowCount;
        }



But it is not working.
Is there any other solution to avoid scroll bar in listbox keeping the size of listbox restricted to the no. of items?
Posted
Updated 20-Mar-15 22:01pm
v2
Comments
Joan Magnet 21-Mar-15 13:27pm    
I'm not sure, but Rows property is saved in viewstate, have you tried to use PreRender event?

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



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