Datagrid Paging not working

C

Coleen

Sorry about the multi-posting, but it does not seem as though the other
newsgroups are frequented enough to get any advice on this problem...If
anyone can possibly help, I would greatly appreciate it, I've spent three
days trying figure out why paging won't work for me...TIA.

I've been to gotdotnet.com/quickstart...samples and reviewed the Source
control for adding paging to datagrids, my problem is that we do not connect
to an SQL Server, we are using an RPC to get the data from a DB2 database
using COBOL. It is a difficult way to get connected, and causes problems
when I'm trying to do something that's supposed to be as simple as paging
for a datagrid. When I select the page number to go to, I get a blank
screen, with Currentpageindex is 1 and PageCount is 0. Why doesn't it page
correctly? Here is my code...Any suggestions?

Dim lo_AZRM001A_SEL As MotorFuel.AZRM001A_SEL
Dim lo_misc_func As MotorFuel.misc_func
Dim ds_mc As DataSet
Dim dt_mc As New DataTable()
Dim createdataview as DataView

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
uf_get_supplier_list()
End If
End Sub

Private Sub uf_get_supplier_list()
'This function gets the Withdrawal listing if available.
'Define the local variables.
Dim li_no_row As Integer = 0
Try
'Instantiate an RPC to get an Withdrawal Listing.
lo_AZRM001A_SEL = New MotorFuel.AZRM001A_SEL()
lo_misc_func = New MotorFuel.misc_func()
Catch
'Destroy the objects.
lo_AZRM001A_SEL = Nothing
lo_misc_func = Nothing
End Try
'Set the data to the Data Grid if the li_no_row is not equal "0".
If li_no_row <> 0 Then
If Page.IsPostBack = False Then
dt_mc = lo_AZRM001A_SEL.get_ddl_sel_sup
dtg_load_data()
End If
End If
'Destroy the objects.
lo_AZRM001A_SEL = Nothing
lo_misc_func = Nothing

End Sub

Private Sub btn_sel_sup_ok_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_sel_sup_ok.Click
Response.Redirect("../Common/mc_rpt_period.aspx")
End Sub

Sub dtg_load_data()
dtg_sel_sup.DataSource = dt_mc
dtg_sel_sup.DataKeyField = "BusinessID"
dtg_sel_sup.DataMember = "BusinessName"
dtg_sel_sup.DataMember = "Account"
dtg_sel_sup.DataBind()
createdataview = New DataView(dt_mc)
'Destroy the objects.
lo_AZRM001A_SEL = Nothing
lo_misc_func = Nothing
End Sub

Sub dtg_sel_sup_Page(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
dtg_sel_sup.CurrentPageIndex = e.NewPageIndex
bindgrid()
End Sub

Sub bindgrid()
dtg_sel_sup.DataSource = createdataview
dtg_sel_sup.DataBind()
showstats()
End Sub

Sub showstats()
lblcurrentindex.Text = "CurrentpageIndex is " &
dtg_sel_sup.CurrentPageIndex
lblpagecount.Text = "PageCount is " & dtg_sel_sup.PageCount
End Sub
 
T

Tu-Thach

you need to re-populate createdataview in your databind()
method. Otherwise, it has no data in it.

Tu-Thach
 
C

Coleen

So here - I need to do something like this?
Sub dtg_load_data()
dtg_sel_sup.DataSource = dt_mc
dtg_sel_sup.DataKeyField = "BusinessID"
dtg_sel_sup.DataMember = "BusinessName"
dtg_sel_sup.DataMember = "Account"
createdataview = New DataView(dt_mc)
dtg_sel_sup.DataBind()

I'm not really sure, since I had already re-bound the datagrid only
difference is that I changed the position of the databind. I'm having
trouble getting a connection to our database right now, so I can't test it.
If this is not what you meant, could you please give me an example? Thanks
very much for the assistance :)

Coleen
 
T

Tu-Thach

Look at your function for handling page change, you have

Sub dtg_sel_sup_Page(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
dtg_sel_sup.CurrentPageIndex = e.NewPageIndex
bindgrid()
End Sub

which calls bindgrid() to bind your datagrid. The
bindgrid method:

Sub bindgrid()
dtg_sel_sup.DataSource = createdataview
dtg_sel_sup.DataBind()
showstats()
End Sub

In this method, you set the datasource for your grid to
the variable createdataview. Nowhere in this code did you
initialize data for the variable createdataview.
Therefore, when you bind the datagrid, it does not have
any data and that's why the datagrid shows nothing. You
need to do something similar to your dtg_load_data()
method.

Tu-Thach
 
C

Coleen

Umm, I totally missed that - Thanks! I guess that's what happens when you
try to do too much multi-tasking...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top