|
-
Jul 2nd, 2005, 10:40 AM
#1
Thread Starter
Junior Member
Datagrid
I am studying on datagrids and this example that i am looking at is from the mircsoft quickstart tutourials at ---> http://samples.gotdotnet.com/quickst..._datagrid.aspx
I have been stuck for three hours nownot understanding how this startIndex is being set. It looks like it the startindex should be 10 more than it actually is. The working example is located at---->(http://samples.gotdotnet.com/quickst..._datagrid.aspx )
Thanks!
Erik...
============I Understand in this sub evnt that if -----HERE---> startIndex = e.NewPageIndex * MyDataGrid.PageSize <-----HERE-----is establishing the page index, =====BUT when i get to the ----HERE----> For i = startIndex To (startIndex + MyDataGrid.PageSize)<----HERE---- it looks like ths is adding more numbers to the start index
Sub MyDataGrid_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
startIndex = e.NewPageIndex * MyDataGrid.PageSize
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
Sub MyDataGrid_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
startIndex = e.NewPageIndex * MyDataGrid.PageSize
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
Function CreateDataSource() As ICollection
Dim dt As DataTable
Dim dr As DataRow
Dim i As Integer
'create a DataTable
dt = New DataTable
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("DateTimeValue", GetType(String)))
dt.Columns.Add(New DataColumn("BoolValue", GetType(Boolean)))
' "query" should return one page of data, beginning at the start index
For i = startIndex To (startIndex + MyDataGrid.PageSize)
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item" + i.ToString()
dr(2) = DateTime.Now.ToShortDateString
If (i Mod 2 <> 0) Then
dr(3) = True
Else
dr(3) = False
End If
dt.Rows.Add(dr)
Next
'return a DataView to the DataTable
CreateDataSource = New DataView(dt)
End Function
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
startIndex = 0
MyDataGrid.VirtualItemCount = 200
End If
BindGrid()
End Sub
Sub MyDataGrid_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
startIndex = e.NewPageIndex * MyDataGrid.PageSize
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
Sub BindGrid()
MyDataGrid.DataSource = CreateDataSource()
MyDataGrid.DataBind()
ShowStats()
End Sub
Sub ShowStats()
lblEnabled.Text = "AllowPaging is " & MyDataGrid.AllowPaging
lblCustom.Text = "AllowCustomPaging is " & MyDataGrid.AllowCustomPaging
lblCurrentIndex.Text = "CurrentPageIndex is " & MyDataGrid.CurrentPageIndex
lblPageCount.Text = "PageCount is " & MyDataGrid.PageCount
lblVirtual.Text = "VirtualItemCount is " & MyDataGrid.VirtualItemCount
lblPageSize.Text = "PageSize is " & MyDataGrid.PageSize
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|