2014年7月13日 星期日

[RESOLVED] Need Help On Gridview Scroll


I am trying to achieve  freezing the gridview 1st column not to be scrollable horizondally. I refer the following article link below,


http://www.xdevsoftware.com/blog/post/Freeze-Pane-in-GridView.aspx.


In my requirement i am bringing the data with column dynamically from database. Basically i am preparing monthly report using PIVOT in database. So i am not using template field/bound field .i am able to get the data and show onto both the grids as per the
logic described on above link blog. But the problem what i am facing is the grid cell width is not aligned properly. i wanted to have both the grid cell size  must be same inorder to have the grid scroll properly.



My code is below.










GridLines="Both" ShowHeader="true"
CellPadding="5" CellSpacing="0" PageSize = "20">






CellPadding="5" CellSpacing="0">




How can i keep the both grid's column width equally to have both the grid's height and look and feel equal. please help me on this.  would bemore helpful if any sample code.





Try setting the GridView cell width on databound event of GridViews


Please try the below implementation



  • Subscribe to OnDatabound event of grid


                            GridLines="Both" ShowHeader="true" OnDataBound="OnDataBound"
CellPadding="5" CellSpacing="0" PageSize = "20">




  • Use the below code to set the columns width dynamically


protected void OnDataBound(object sender, EventArgs e)
{
//Here we are setting column width to first cell, you can set width to to other columns as per your need
this.gvFreeze.Rows[0].Cells[0].Width = Unit.Pixel(150);
}

Follow the same for second gridview also





Thank you A2H. appriciate your time on this thread and will post you the result once i complete this requirement. please stay tune.



Hi A2h,


Finally i achieved by setting header style for the gridview  aswell as your sugestion. thanks for the hint.


沒有留言:

張貼留言