3

I have a gridview on my page which is shown below

<div style="overflow-x:scroll; width:100%; height:255px">
                        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="Horizontal"
                            BorderStyle="Solid" BorderColor="Black" AllowPaging="false" PageSize="4" OnPageIndexChanging="GridView1_PageIndexChanging" Height="235px"
                            width="90%" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="false" 
                            RowStyle-Height="37px" HeaderStyle-Height="40px" FooterStyle-Height="40px">
                            <Columns>
                                <asp:BoundField HeaderText="ID" DataField="UserID" />
                                <asp:BoundField HeaderText="User Name" DataField="UserName" HeaderStyle-HorizontalAlign="Center"/>
                                <asp:BoundField HeaderText="User Role" DataField="UserRoleName"/>
                            </Columns>
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <EditRowStyle BackColor="#999999" />
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#2e85c2" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
                            <PagerStyle BackColor="#2e85c2" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Bottom" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                        </asp:GridView>
                        </div>

This works fine and so does the selectedindexchanged method below

protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
        {
            GridViewRow row = GridView1.SelectedRow;
            int sd = int.Parse(row.Cells[0].Text);
            removeUserButton.Enabled = true;
            GridView1.Focus();
        }

but when I select an item from the bottom of the gridview it resets the scrollbar and you cannot see what is selected without scrolling down. Is there a way to prevent the extra scrolling on the page?

David Hall
  • 32,624
  • 10
  • 90
  • 127
Win
  • 2,593
  • 3
  • 25
  • 35

4 Answers4

0
max-height:255px

<div style="overflow-x:scroll; width:100%; max-height:255px;">
sangram parmar
  • 8,462
  • 2
  • 23
  • 47
0

try to set below property of GridView on GridView1_SelectedIndexChanged event.

dataGridViews1.ScrollBars = ScrollBars.None;
Jack
  • 253
  • 3
  • 8
0

Just in case anyone is looking at this at a later date, I never managed to fix the issue but found that Telerik has a radgrid that my company used so I just used that and it fixed the issue. not the ideal solution but it did the job.

Win
  • 2,593
  • 3
  • 25
  • 35
0

I got to deal with this problem too. The solution I see on this is to set pagination of the gridview. With that, you'll be displaying a set number of rows per page preventing the use of scollbars. Hope this gives you an idea

Thanks.

cracker_chan
  • 93
  • 1
  • 3
  • 11
  • That is something I did to prevent it but I am facing another issue, If you can help that'd be great. http://stackoverflow.com/questions/38069425/gridviews-horizontal-scrollbar-resets-its-position-when-modalpopextender-is-ope – Akshay Jun 28 '16 at 07:25