This is a migrated thread and some comments may be shown as answers.

[Solved] Grid ItemCommand not firing

7 Answers 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron Buchanan
Top achievements
Rank 1
Ron Buchanan asked on 23 Dec 2009, 02:02 PM
I have a grid on the page that has an edit button on each of the rows. Initially, I had a link with an image that would go to the correct edit page. However, I now need to do some processing before going to the edit page. I have tried several methods and none of them are working as expected.

1. Use GridEditCommandColumn and catch the ItemCommand event of the grid.
2. Use a template column with a button and catch the Click event of the button.
3. Use a template column with a button and set the CommandName and catch the ItemCommand event of the grid.

At this time, there are no errors. In all of these methods the grid will postback, but it does not reach the event. It will go through the Page_Load event, and then come back to the page.

UPDATE:

I am doing advanced databinding on the grid and the order of events seems to be Page_Load and then NeedDataSource. It appears to stop after this event. Also, ViewState is turned off.

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Dec 2009, 06:29 AM
Hi,

The reason behind this behaviour is that when you turn off the Viewstate of the grid the  button that generated the ItemCommand event isn't there when the event is raised on the server.So I would suggest turning on the viewstate of the RadGrid.
You can check out the links below for  a more deeper understanding ...
http://www.telerik.com/help/aspnet-ajax/grdviewstateoptimization.html
http://www.west-wind.com/WebLog/posts/4560.aspx
http://msdn.microsoft.com/en-us/library/ms972976.aspx

Thanks,
Princy



0
Ron Buchanan
Top achievements
Rank 1
answered on 26 Dec 2009, 02:11 AM
Originally, I had ViewState turned on. However, I removed it because we have a separate area for entering filter information, and each time we tried to filter the grid, it would remember the last result and continue filtering on the initial request. Is there a way to clear the ViewState in this instance? I am using advanced databinding as it is and have implemented the NeedDataSource event.
0
Ron Buchanan
Top achievements
Rank 1
answered on 27 Dec 2009, 07:28 AM
UPDATE:

I changed the EnableViewState to true, and now the event is firing as expected. However, now there is another issue. If I try a Server.Transfer or a Response.Redirect inside the ItemCommand event, there is an unknown error. It runs the target Page_Load without a problem, but then the page just comes back to its current state. Anyone seen this before?

UPDATE:

I have been pleased with the Telerik RadGrid so far, but this is something so trivial that seems to be so difficult to handle. Here is the scenario:

1. Enter filtering criteria in a form above the grid and click the search button.
2. Grid requests data from paging stored procedure sending all the necessary filter criteria.
3. If the user clicks the edit button then it navigates the user to a separate page completely (not a RadWindow) and saves the filter information as well as the paging information of the grid.
4. When the user returns from the editing page (if they return), then the grid and filter criteria are pulled from the Session and everything is back to normal.

To get this to work correctly before, I was using NeedDataSource. However, I had to have EnableViewState on and I didn't want that, for various reasons. So, I turned it on to get the button event to fire. This did not work because I could not do a Server.Transfer or a Response.Redirect within the ItemCommand event. Now, I am on the last thing that I can think of and that is to store the information during the rebind within the NeedDataSource event since the only time this happens. If I don't store the information, everything works. Once I try to store the information, the databinding itself stops working. What I mean by this is that the data comes back from the database in a DataTable, it has no problem assigning the DataSource property, but the grid doesn't show anything. Anyone have a clue on this one? How could Session possibly interfere with NeedDataSource or a RadGrid's databinding?
0
Tsvetoslav
Telerik team
answered on 29 Dec 2009, 08:50 AM
Hi Ron,

Try using the RadAjaxManager control to redirect to the desired page as described in the following help article:
http://www.telerik.com/help/aspnet-ajax/ajxredirectingtoanotherpage.html

You may find the following help topic useful as well:
http://www.telerik.com/help/aspnet-ajax/ajxcontenttype.html

However, if the problem still persists, I'd ask you to open a formal support ticket and send us a test project of your implementation for closer inspection.

Thanks.

Best wishes,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ron Buchanan
Top achievements
Rank 1
answered on 29 Dec 2009, 01:57 PM
Well, I was going to go that route, but I decided to try another since I had spent so much time but wasn't getting anywhere. At this point what I am doing is advanced data binding based on information in the examples. Here is the code:

        protected void Page_Load( object sender, EventArgs e ) 
        { 
            if( !Page.IsPostBack ) 
            { 
                submissionDateFromRadDatePicker.SelectedDate = DateTime.Now.AddMonths( -1 ); 
                submissionDateToRadDatePicker.SelectedDate = DateTime.Now; 
 
                if( this.LoadPrivateState() ) 
                { 
                    this.LoadGrid(); 
                } 
            } 
            else 
            { 
                this.SavePrivateState( true ); 
            } 
        } 
 
        protected void RadGrid1_NeedDataSource( object source, GridNeedDataSourceEventArgs e ) 
        { 
            if( ( Page.IsPostBack ) && ( this.FiltersSelected() ) ) 
            { 
                this.LoadGrid(); 
            } 
        } 
 
        private void SavePrivateState( bool saveState ) 
        { 
            if( saveState ) 
            { 
                // ... Other work 
 
                // TODO: Why does this statement interfere with binding the RadGrid? 
                Session[ "ClaimStatusReportStateObject" ] = privateState; 
            } 
            else 
            { 
                Session.Remove( "ClaimStatusReportStateObject" ); 
            } 
        } 
 
        private void LoadGrid() 
        { 
            RadGrid1.DataSource = this.GetDataTable(); 
        } 
 

All of this works fine except for the one line marked with TODO. If I comment out this line, everything works, but it does not save the state of the grid, which is the most important part. If I don't comment out this line, then the GetDataTable() method will return a valid DataTable with data, it will not throw an exception when assigning this to the RadGrid1.DataSource, but the page will not show the data. The RadGrid appears a few pixels thick.
0
Yavor
Telerik team
answered on 04 Jan 2010, 10:56 AM
Hello Ron,

Based on the supplied information, it is hard to determine what is causing this unwanted behavior.
To further track the issue, it will be best if you open a formal support ticket, and send us a small working project, demonstrating this unwanted behavior. We will debug it locally, and advise you further!

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ron Buchanan
Top achievements
Rank 1
answered on 04 Jan 2010, 01:27 PM
I finally figured out the issue. Basically, advanced databinding, etc. is all fine. The real issues, like I said was storing the object in the Session. Once I stopped storing it in the Session and stored the individual primitives, everything worked just fine. I am not sure if this is bug worthy or just something to watch out for. I know it took me a bit to figure out. ;)

Tags
Grid
Asked by
Ron Buchanan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ron Buchanan
Top achievements
Rank 1
Tsvetoslav
Telerik team
Yavor
Telerik team
Share this question
or