GridView: How to set the number of rows to display

牧云@^-^@ 提交于 2019-12-23 07:27:25

问题


I would like my grid view to display only 3 rows any ideas on how I can achieve this?

Thanks


回答1:


Enable Paging and set the GridView's PageSize to 3.

How to: Enable Default Paging in the GridView Web Server Control

If you want to restrict your GridView to show only 3 rows without paging, you need to use a DataSource with only 3 records (f.e. via SQL-TOP-Clause or Limit in MySQL or LINQ's Take(3)).




回答2:


If you can limit the records in your query, then that's the best approach.

However, if you can't limit them in the query... here is another approach:

  1. Set "allowpaging=true" and "pagesize=X" (change X to how many rows you want visible).
  2. Assign a pagerstyle with a custom CSS class.

    <pagerstyle cssclass="hidden" />

  3. Set that custom class to:

    .hidden { visibility: hidden; display: none; }

Now, your grid will use the paging logic, but the pager controls are hidden.

It's not the cleanest/most elegant, but it works.




回答3:


place AllowPaging="True" and PageSize="3" in GridView




回答4:


I'd keep it simple and ensure your DataSource only provides the three rows of data you need to display.

Failing that, you could set the .Visible property of all Rows to false, except Rows[0] through Rows[2].




回答5:


2 ways that i can think of.....

  1. Get your dataset from your query.
  2. Create columns and add to your gridview...
  3. Add 3 rows on a button click and keep the index static
  4. On the same click, clear your grid and add next three rows....

OR

Use paging!!!!!!




回答6:


go to view and click on grid and a small overlay opens allowing (requiring you) to enter a number for the column. then preview and click save




回答7:


you can use Repeater instead as follow.

<asp:Repeater ID="Repeater2" runat="server" >
<HeaderTemplate>
<table class="center">
    <tr>

<%#If((Container.ItemIndex <> 0 AndAlso Container.ItemIndex Mod 4 = 0), " ", String.Empty)%> ' PostBackUrl='<%# Container.DataItem("url")%>' >

</asp:Repeater>


来源:https://stackoverflow.com/questions/10227218/gridview-how-to-set-the-number-of-rows-to-display

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!