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

[Solved] Update and Cancel CommandItemTemplate buttons do not fire

2 Answers 408 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Babu Mannaravalappil
Top achievements
Rank 1
Babu Mannaravalappil asked on 04 Nov 2009, 07:18 PM

Hi,

I have two issues.

1.  I have a RadComboBox whose selectedIndex to be reassigned at runtime based on some other actions on the page.  Though I tried setting the ComboBox.SelectedIndex = some number, ComboBox.SelectedValue = some value   - None of the ways I tried seem to work.  The Combo.SelectedItem still stays as the old selected item.  Does not change.  What am I doing wrong?

2.  I have three Image buttons in a CommandItemTemplate on my RadGrid.  These buttons are "Editall", "UpdateAll" and "CancelAll". 

Update and cancel button are initially hidden and the only button visible is Edit.  These buttons are meant to make the grid

bulk-editable and bulk-updateable.  I don't have any per row Command Items.  All the columns are created at runtime.  On inital page load, everything seem to be normal and I can only see the Edit button as expected.  When I click the button, the Grid goes goes into Edit mode (I have the code in ItemCommand event handler).  At this point I can only "see" the Update and Cancel buttons on the Command bar (again as expected).  But the problem is nothing happens when I click on either the update button or the Cancel button.  Seemingly, no event handlers get called.  What am I doing wrong?   I can give you a clue about the scenario.  If I have all the three buttons visible on the initial page load, and I click the Update button, the ItemCommand event handler does get called.  But none of the buttons fires any events on any subsequent page loads.  So, I am thinking, there must be something wrong with my postbacks.  Here is my code.  Please tell me where all do I have to do the ReBind(). The code fragment is partial only.

My aspx file:

<telerik:RadGrid ID="rgForecast" runat="server" AllowSorting="True" AutoGenerateColumns="False"
   ShowStatusBar="True" Width="800px" Skin="Forest" OnNeedDataSource="rgForecast_NeedDataSource"
   OnPreRender="rgForecast_PreRender" GroupingEnabled="False" OnItemCommand="rgForecast_ItemCommand"
   OnItemCreated="rgForecast_ItemCreated" AllowMultiRowEdit="True">
   <MasterTableView CommandItemDisplay="Top" EditMode="InPlace">
    <CommandItemTemplate>
     <div id="EditButtonDiv" runat="server" style="position: relative; float: left;

padding-right: 20px;">
      <asp:ImageButton ID="EditGrid" Text="Edit Items" AlternateText="Edit"

runat="server"
       CommandName="EditAll" ImageUrl="~/Images/Edit.gif" ToolTip="Click to Edit

the Grid" />
     </div>
     <div id="UpdateButtonDiv" runat="server" style="position: relative; float: left;

padding-right: 20px;">
      <asp:ImageButton ID="UpdateGrid" Text="Update Items" AlternateText="Update"

runat="server"
       CommandName="UpdateAll" ImageUrl="~/Images/Update.gif" ToolTip="Click to

update the Grid" />
     </div>
     <div id="CancelButtonDiv" runat="server" style="position: relative; float: left;

padding-right: 20px;">
      <asp:ImageButton ID="CancelUpdate" Text="Cancel Updates" AlternateText="Cancel"

runat="server"
       CommandName="CancelAll" ImageUrl="~/Images/Cancel.gif" ToolTip="Click to

cancel updates" />
     </div>
     <div style="position: relative; float: right; padding-right: 20px;">
      <asp:ImageButton ID="Export2Excel" Text="Export to Excel" AlternateText="Excel

Export" runat="server"
       CommandName="ExportToExcel" ImageUrl="~/Images/MoveUp.gif" ToolTip="Click

to Export grid to Excel" />
     </div>
    </CommandItemTemplate>
   </MasterTableView>
   <ClientSettings>
    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
   </ClientSettings>
   <EditItemStyle BackColor="#FFFF99" />
   <SortingSettings SortedAscToolTip="Sorted Asc" SortedDescToolTip="Sorted Desc" />
   <StatusBarSettings LoadingText="Loading. Please wait....." />
  </telerik:RadGrid>

My cs file:

 protected void rgForecast_PreRender(object sender, EventArgs e)
 {
  RadGrid grid = (RadGrid)sender;
  foreach (GridColumn col in grid.Columns)
  {
   if (Array.IndexOf(strInvisibleCols, col.UniqueName) >= 0)
    col.Visible = false;
   else
   {
    col.ItemStyle.Wrap = false;
    col.HeaderStyle.Wrap = false;
   }
  }
  //grid.Rebind();
 }

 

 protected void rgForecast_ItemCommand(object source, GridCommandEventArgs e)
 {
  if (e.CommandName == "UpdateAll")
  {UpdateGrid();}
  else if (e.CommandName == "EditAll")
  {EditGrid();}
  else if (e.CommandName == "CancelAll")
  {CancelUpdate();}
  //rgForecast.Rebind();
 }

 

 protected void rgForecast_ItemCreated(object sender, GridItemEventArgs e)
 {
  if (e.Item is GridCommandItem)
  {
   GridCommandItem commandItem = e.Item as GridCommandItem;
   ImageButton btnEdit = commandItem.FindControl("EditGrid") as ImageButton;
   btnEdit.Visible = IsKeyerUser((string)Session[Role]) && rgForecast.EditIndexes.Count == 0;
   ImageButton btnUpdate = commandItem.FindControl("UpdateGrid") as ImageButton;
   btnUpdate.Visible = rgForecast.EditIndexes.Count > 0;
   ImageButton btnCancel = commandItem.FindControl("CancelUpdate") as ImageButton;
   btnCancel.Visible = rgForecast.EditIndexes.Count > 0;
  }

 }

Please help!!

Babu.
 

2 Answers, 1 is accepted

Sort by
0
Babu Mannaravalappil
Top achievements
Rank 1
answered on 05 Nov 2009, 01:06 PM
OK.  I have narrowed down the problem further.

I made all the buttons (Image buttons) visible in the command item bar at the top of the grid.  The first time the grid loads, I am able to click on any one of these buttons (Edit, Update or Cancel) and the "ItemCommand" event is fired and I can handle the button that was clicked.  But when the page refreshes, clicking any one of these buttons have no effect at all.  None of the events seem to respond to the clicks.  What gives?  My guess is something changes when the page is repainted after the postback.  I don't know if I am doing something that I am not supposed to or if I am not doing something I am supposed to.

I read somewhere in the documentation (I can't find it now) that if I name the "CommandName" property of these buttons in certain phrases, the grid will fire the events on its on.  Currently I have named them "DoEdit", "DoUpdate" and "DoCancel".  I have also tried with many different values for the CommandName property.  The bottom line is, no matter what the names are, the "ItemCommand" event is fired only on the first load of the grid.  Not on the subsequent ones.

Somebody please help.  I am getting really frustrated with this.

Babu.

P.S: I still have the SelectedIndex problem with the ComboBox as well.

0
Pavlina
Telerik team
answered on 10 Nov 2009, 09:06 AM
Hi Babu,

Generally you can handle any command, using the ItemCommandEvent. For more information about how to achieve the desired functionality I suggest you review the following articles devoted on the same matter.
Command Item
Command item template

Additionally, SelectedValue returns the correct value on our side - see our online example for a reference.

Greetings,
Pavlina
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.
Tags
Grid
Asked by
Babu Mannaravalappil
Top achievements
Rank 1
Answers by
Babu Mannaravalappil
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or