How to control column count for profiles of generated gridview fields
I have a gridivew with auto-generated fields, whenever a new dataset appears, I will add a grid with data. Is there a way to set bounded columns (like 6) to force the user to go to the next page? instead of keeping the addition until it's super ugly?
Example:
so there could be a class (12 July 2012), a class (4 April 2013), etc ...
although i can find the pages but i cant find the columns!
Edited:
I manage to add a scrollbar to the bottom of the gridview. However, the grid with autogenerated columns tends to be a bit clustered. (if you notice the column of names from the second picture). Can anyone please help?
code:
<asp:Panel ID="ScrollPanel" style="Width:1300px;" runat="server" ScrollBars="Horizontal">
<asp:GridView ID="ViewAllHistory" runat="server" BorderWidth="1px"
CellPadding="2" CellSpacing="2" AllowPaging="True" BackColor="Black"
onpageindexchanging="ViewAllHistory_PageIndexChanging" PageSize="10">
<RowStyle BackColor="White"/>
<FooterStyle BackColor="#CCCCCC" />
<PagerSettings Position="TopAndBottom" />
<PagerStyle HorizontalAlign="Center" BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</asp:Panel>
only when i correct the grid width then the design looks better. But I would hate to fix my grid width considering a new dataset is coming in. (Long term)
Change Column Collection
One way to do this is to have all the columns you need already in your data source and then just change Columns
yours GridView
. So, for example, you have a button that adds a column, and you do it in this click:
protected void Button1_Click(object sender, EventArgs e)
{
BoundField newCol = new BoundField();
// This string needs to be the name of the column in your datasource
newCol.DataField = "Grade12July2012";
// Whatever you want the column header to say
newCol.HeaderText = "Grade(12 July 2012)";
GridView1.Columns.Add(newCol);
GridView1.DataBind();
}
Use a scrollable<div>
container
As alex said in the comments , another way to do this would be to simply put a scrollable container around yours GridView
. This way you can have all the columns without taking up too much screen real estate:
<div id="gridContainer" style="width:200px; overflow:scroll; height:auto;">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
source to share