This is a migrated thread and some comments may be shown as answers.

change height grid when change page size

3 Answers 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 17 Jul 2013, 02:26 PM
hello,
I would like to manage code behind that when I change the display of rows of the grid, for example from 20 to 30 or 50 lines, automatically changes the height of the grid. I set the default 15 lines and a height of 485px. How can I do?

this is the code that I use when I change the page size

Protected Sub RadGrid1_PageSizeChanged(sender As Object, e As GridPageSizeChangedEventArgs) Handles RadGrid1.PageSizeChanged
    RadGrid1.DataSource = read.GetSchedineData(1, "15-07-2013")
    RadGrid1.Rebind()
End Sub

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Jul 2013, 02:41 PM
Hello,


Please try with the below code snippet.


protected int GridWidth
    {
        get
        {
            if (ViewState["GridWidth"] == null)
            {
                return 450;
            }
            else
            {
                return (int)ViewState["GridWidth"];
            }
             
        }
        set
        {
            ViewState["GridWidth"] = value;
        }
    }
 
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            GridWidth = 450;
        }
    }
 
    protected void Page_PreRender(object sender, System.EventArgs e)
    {
        RadGrid1.Height = Unit.Pixel(GridWidth);
        //OR
        RadGrid1.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(GridWidth);
    }
    protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
    {
        GridWidth = 900;
    }


Thanks,
Jayesh Goyani
0
Fabio Cirillo
Top achievements
Rank 1
answered on 18 Jul 2013, 10:16 AM
it works ok but lla new height is set to 900px I wish that the new height fit with the number of rows displayed also including the height of the paging file.

look at the modified image with height = 900, you can see that after the slash management pages, there is an empty space, I wish this did not happen

0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Jul 2013, 12:51 PM
Hello,

For that you have to manage this thing manually.

Please measure GridHeaderHeight, GridPagerHeight and GridRowHeight From browser and Replace its value in below code snippet.

To measure heigh you can also use "jruler" or any browser add-on.

protected void Page_PreRender(object sender, System.EventArgs e)
    {
        
       int GridWidth = (GrdiHeaderHeight + GridPagerHeight  + (RadGrid1.MasterTableView.Items.Count * GridRowHeight)) ; 
  
        RadGrid1.Height = Unit.Pixel(GridWidth);
        //OR
        RadGrid1.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(GridWidth);
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Fabio Cirillo
Top achievements
Rank 1
Share this question
or