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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid OnItemCommand... Stops Paging... 1

Status
Not open for further replies.
Feb 4, 2002
792
GB
Hi all,

Can anyone help with this? I suppose this is an ASP.NET issue, but I forgot to look to see if Tek-Tips had a separate forum... and I've already started typing... so...

I have a DataGrid on my aspx page, that has a button loaded in each row that adds to cart. The button works perfectly and took me the best part of two weeks of poring over the VS.NET documentation to firgure out how to do this!!
But now my paging doesn't work. I know exactly why it's not working... I just don't know how to get around the problem... can anyone help?

The problem is that since I added the Add To Cart button, I had to include a paramter called CommandName, with a string vale "AddToCart"... I then use this in a CartButton_Clicked(...) event to handle the code I want executed for when this button is clicked...
So the ItemCommand in the DataGrid is "CartButton_Clicked"

This all works a treat!, but now when I click Next> to go to the next page, the paging tries to call the CartButton_Clicked method, instead of the DataGrid_PageIndexChanged method!! I can't figure out why... so when the event is fired, it is interpreted by the Button's DataGridCommandEventArgs e object, rather than the Page Index method's DataGridPageChangedEventArgs e object.

I tried setting OnPageIndexChanged to ="DataGrid1_PageIndexChanged" within the DataGrid tag, but this also doesn't work...

Will
 
I have the same problem, I've paging and sorting going on but as soon as I put an OnItemCommand method in the datagrid, this method over rides the OnPageIndexChanged and OnSortCommand methods, it's insane!

"Do not attribute to Malice, what can easily be explained away by stupidity" REF 2002
 
I'm having the exact same problem. Did you ever find a solution?
 
Ok, I found a solution (not sure if it is the best). When I added the ItemCommand event, my paging clicks were calling that method as opposed to the default paging method it was using.

I added the attribute:

OnPageIndexChanged='event_Page'

to my datagrid, and I created this small method:

private void event_Page(object sender, DataGridPageChangedEventArgs e) {
eventGrid.CurrentPageIndex = e.NewPageIndex;
bindEventGrid();
}

Seems to be working fine.
 
I found a similar way around it. If in the method called by the onItemColmmand you specify the itemCommand word you want to use, when you try to page, asp still goes straight to the onItemCommand method but because the paging command word will not be linked there, it will then go to the paging method. I think it's abug in asp personally. I was getting with sorting and filtering aswell, and now it fine!

"Do not attribute to Malice, what can easily be explained away by stupidity" REF 2002
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top