Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling pagination in a dg

Status
Not open for further replies.

OhioSteve

MIS
Mar 12, 2002
1,352
US
I am trying to fix a datagrid that I made many months ago. On this datagrid, my intent was to have one function handle any event on the dg initially. This function was called switchboard, and it either handled the event immediately or redirected the event to the appropriate handler. It works okay except for the event that paginates.

Here is the html for the dg~

<asp:datagrid
id=DataGrid1 runat="server" OnSortCommand="SortEventHandler" OnItemCommand="mySwitchboard" Width="400px" Height="250px" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" DataSource="<%# DataSet11 %>" DataMember="audit_Location" DataKeyField="locationid" AutoGenerateColumns="False" AllowPaging="True" PageSize="5" AllowSorting="True" >

Here is mySwitchboard~
Public Sub mySwitchboard(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)


Dim a As String = e.CommandName.ToString
Label1.Text = a
If a = "Page" Then
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
Return
End If
If a = "nextWebPage" Then
nextWebPage(e)
ElseIf a = "Edit" Then
editDataGridRow(e)
ElseIf a = "Cancel" Then
cancelEdit()
ElseIf a = "Update" Then
updateDataGridRow(e)
End If

End Sub

The blue line of doom is under e.NewPageIndex :(
So I need to either finish implementing the switchboard idea, or handle the pagination separately.
I will be happy to take your suggestions on either approach.
 
You will have to use the DataGrid1_PageIndexChanged event for this. I am not sure how your swichboard is working since it is not really "wired" to a particular event.
 
Code:
Add Handles DataGrid1.PageIndexChanged,

datagrid1.<event>, ...

for each event you want your sub to handle
 
You were right. I added this, and everything worked:

Protected Sub DataGrid1_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged

DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()


End Sub

So right now, I have some things going through the switchboard, but not all. The results are good but it seems like an untidy system.

I would expect to see a one-to-one relationship. In the html, I would expect to see

OnACommand="AEventHandler"
OnBCommand="BEventHandler"
OnCCommand="CEventHandler"

Then on the code-behind, I would expect to see separate handlers for A, B, & C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top