Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want that there should be a gridview with

1) Scrollbar
2) Up button - so that scrollbar should move up
3) down button- so that scrollbar should move down
4) A label where the total number of records are shown

I am not able to get all the above mentioned features please reply
Posted
Updated 18-May-11 1:20am
v2

For qns 1-3
Put the GridView inside a code div or a Panel control.
1. If you use in div
<div style="vertical-align top; height: 152px; overflow:auto;width:800px;">
       <asp:GridView ID="myGridView" runat="server" AllowPaging="True" AllowSorting="True"  OnRowCreated="myGridView_RowCreated">
</asp:GridView>
</div>

2. If you use Panel
<asp:Panel ID="myGridViewPanel" runat="server" ScrollBars="Vertical">
    <asp:GridView ID="myGridView" runat="server" AllowPaging="True" AllowSorting="True"  OnRowCreated="myGridView_RowCreated">
    </asp:GridView>
</asp:Panel>


For qn 4.
/// <summary>
/// Occurs when a row is created in the grid view control.
/// </summary>
protected void myGridView_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
    if (myGridView.DataSource != null)
        lblRecord.Text = ((IList)myGridView.DataSource).Count.ToString(); // Assuming that your GridView is binded to List collection.
}


I hope this will help you well.
 
Share this answer
 
v2
Comments
Nithin Sundar 18-May-11 23:25pm    
My 5! This is a great solution.
Wonde Tadesse 6-Dec-11 10:43am    
Thanks
senguptaamlan 19-May-11 1:21am    
my 5
Wonde Tadesse 6-Dec-11 10:44am    
Thanks
According to this:

DataGridView - Scrollbars (MSDN)[^]

"Regardless of the value of this property, scroll bars are shown only when they are needed. Use this property to prevent scroll bars from appearing. This is useful, for example, when you want to provide an alternative user interface (UI) for scrolling."

You should be getting the scrollbar if the number of records displayed in the DataGridView go beyond the size of the grid itself on the display.
 
Share this answer
 
v2
Comments
Wonde Tadesse 18-May-11 7:29am    
Asp.Net grid view does not have a scrollbars property. :(
Nithin Sundar 18-May-11 7:40am    
Okay but my point is that even if the property isn't present I think it automatically adds them. I've used DataGridView in a ASP .NET Web app and I believe that I did see a scrollbar when the number of records went past the size I defined for the control or so!
Wonde Tadesse 18-May-11 12:05pm    
Please look my answer.

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