Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Jun 6, 2024, 5:02 AM EDT
To add a horizontal scrollbar to the top of an ASP.NET GridView, you can use a combination of HTML and CSS. Unfortunately, there’s no built-in way to do this, but you can achieve it with a bit of custom code.
Here’s a simple example of how you can do it:
And the corresponding CSS:
.outer { overflow-x: auto; overflow-y: hidden; height: 20px; } .inner { overflow: auto; overflow-y: hidden; height: 20px; margin-bottom: -20px; padding-bottom: 20px; }In this example, the
.outerdiv creates the scrollbar at the top, and the.innerdiv contains the GridView and creates a second scrollbar at the bottom. The negative margin on the.innerdiv hides the bottom scrollbar, so only the top one is visible.Please note that this is a workaround and might not work perfectly in all situations or with all types of content. It’s always a good idea to test thoroughly with your specific GridView and content. Also, keep in mind that this might not provide the best user experience, as users are generally accustomed to scrollbars being at the bottom.
Thanks
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jun 6, 2024, 2:22 AM EDT
To achieve this functionality in an ASP.NET GridView, you can use JavaScript to scroll the GridView horizontally to the top.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.Attributes.Add("style", "overflow-x:auto; overflow-y:hidden; max-height:300px;"); // Set GridView height and enable horizontal scrollbar } }