Webmaster Forums Banner Professional Hosting from Just Host
Welcome Guest Search | Active Topics | Members | Log In | Register

restrict no of rows in gridview control Options
Razi
Posted: Thursday, May 22, 2008 8:24:28 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2008
Posts: 41
Points: 123
Location: India
hi

can we restrict max no of rows in gridview control? if yes how we can do that

many thanks
Sponsor
Posted: Thursday, May 22, 2008 8:24:28 AM
sachin
Posted: Thursday, May 22, 2008 12:14:38 PM
Rank: Advanced Member
Groups: Member

Joined: 3/3/2008
Posts: 79
Points: 237
Location: India
you can do it by enabling paging of gridview and defining page size property.

hope that helps

thanks
Razi
Posted: Friday, May 23, 2008 8:48:47 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2008
Posts: 41
Points: 123
Location: India
well i'm using CSLA datasource. paging is not solution of my problem

my business object serve other controls in the page too. so i can not edit datasource.



can you explain me further how to tell gridview to display only first 3 rows.



many thanks
ca4nul
Posted: Friday, May 23, 2008 8:51:45 AM

Rank: Advanced Member
Groups: Member

Joined: 11/9/2007
Posts: 223
Points: 575
Location: UK
well this works , tested

Code:
Protected Property RowCount() As Integer

Get
Return _RowCount

End Get
Set(ByVal value As Integer)

_RowCount = value

End Set

End Property

Private _RowCount As Integer = 0
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

If e.Row.RowType = DataControlRowType.DataRow Then

RowCount = RowCount + 1

If RowCount > 3 Then

e.Row.Visible = False

End If

End If

End Sub


---------------

Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID"

DataSourceID="SqlDataSource1" onrowdatabound="GridView1_RowDataBound">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"

ReadOnly="True" SortExpression="ProductID" />

<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />



</Columns>

</asp:GridView>
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by HaqTech.Com
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 1.316 seconds.