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

RadGrid, TemplateColumn and ImageButton

13 Answers 263 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mattia
Top achievements
Rank 1
Mattia asked on 30 Jun 2011, 03:35 PM

Hi all,
I have a Rad grid with a column template like the following:

<telerik:GridTemplateColumn HeaderText="Actions" UniqueName="Actions">
 <ItemTemplate>
 <div class="sfBasicLangs">
  <asp:ImageButton runat="server" CommandName="delete" OnCommand="Delete" />
 </div>
</ItemTemplate>
</telerik:GridTemplateColumn>

the Delete method present in the OnCommand is never fired.... how can  have radGrid fire it.
I've already tried to enable viewstate on the grid

Thanks,
Mattia

13 Answers, 1 is accepted

Sort by
0
Mattia
Top achievements
Rank 1
answered on 01 Jul 2011, 10:49 AM
Someone...
0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Jul 2011, 11:35 AM
Hi,

method 1 :

<
asp:ImageButton runat="server" CommandName="Userdelete"
>

ItemCommand()
{
    if(e.CommandName == "Userdelete")
    {
      // write your logic here
     }
}

method 2 :

<
asp:ImageButton runat="server" CommandName="Delete"
>

Deletecommand()
{
   // wrote your logic here
}

Thanks,
Jayesh Goyani
0
Mattia
Top achievements
Rank 1
answered on 01 Jul 2011, 11:56 AM
Hi Jayesh,
thanks for the answer but I have already implemented the Delete function... The problem is that the function is never fired.

Thanks,
Mattia
0
Princy
Top achievements
Rank 2
answered on 01 Jul 2011, 12:09 PM
Hello Mattia,
I was unable to recreate the issue at my end. Please make sure that you have attached the event correctly. Here am pasting the full code.
aspx:
<telerik:RadGrid AllowAutomaticUpdates="true" ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"
   AllowPaging="True" CellSpacing="0" GridLines="None" OnItemCommand="RadGrid1_ItemCommand">
  <MasterTableView DataKeyNames="OrderID" PageSize="10" AllowFilteringByColumn="true" CommandItemDisplay="Top" AutoGenerateColumns="False" EditMode="InPlace">
    <columns>
      <telerik:GridBoundColumn DataField="ShipCountry" FilterControlAltText="Filter ShipCountry column" HeaderText="ShipCountry" SortExpression="ShipCountry" UniqueName="ShipCountry">
      </telerik:GridBoundColumn>
      <telerik:GridTemplateColumn HeaderText="Actions" UniqueName="Actions">
         <ItemTemplate>
           <asp:ImageButton ID="ImageButton1" runat="server" CommandName="delete" OnCommand="Delete" />
         </ItemTemplate>
      </telerik:GridTemplateColumn>               
     </Columns>             
 </MasterTableView>      
 </telerik:RadGrid>

C#:
protected void Delete(object sender, CommandEventArgs e)
   {
   }
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
   }

Thanks,
Princy.
0
Mattia
Top achievements
Rank 1
answered on 01 Jul 2011, 03:29 PM
Hi,
i found the problem. The command is fired only if I do the databinding in the Page_Load.
The problem is that I need to have the value of a dropdown to filter the datasource and, as far as the Page_Load event if fired before the controls event I always get the old value.
If I can only bind the grid in the page load how I can I accomplish this?

Thanks,
Mattia
0
Mira
Telerik team
answered on 05 Jul 2011, 08:54 AM
Hello Mattia,

Please examine this help topic to see how the desired functionality can be implemented.

I hope it helps.

Kind regards,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Mattia
Top achievements
Rank 1
answered on 05 Jul 2011, 08:59 AM
Thanks Mira,
I solved my problem by binding the grid with a objectDataSource instead of manually doing it in dropdown onSelectedIndexChanged event.
But I still don't understand why if I do it manually in the onSelectedIndexChanged event the commands are not fired. 

Thanks,
Mattia
0
Mira
Telerik team
answered on 05 Jul 2011, 01:36 PM
Hello Mattia,

In order the RadGrid to work correct, you should data-bind it properly.
Please examine the Telerik RadGrid data binding basics help topic and the Data-binding help section for additional information.

I hope this helps.

All the best,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
bharath
Top achievements
Rank 1
answered on 11 Mar 2015, 02:30 PM
Hi Jayesh Goyani,

 i have asp:imageButton in radgrid templete column.When i click on the imagebutton i am getting javascript runtime error "unable to get the property 'style' of undefined or null reference. this is comming only on IE.when i run the page in crome script  error is not coming.i added style property to image button.

 With Regards
 Bharath.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Mar 2015, 05:17 PM
Hello,

If I am not wrong than this is the IE version specific issue. Please make sure you used latest telerik version.

If you are not able to resolved this issue than please provide your code snippet.

The error was thrown from dadgrid's in-built js file. So, if we add the external style than also it will not resolved your existing issue.

Let me know if any concern.

Thanks,
Jayesh Goyani
0
bharath
Top achievements
Rank 1
answered on 11 Mar 2015, 08:16 PM
Hi Jayesh,

 My radgrid inside the update panel.When i removed update panel i am not getting the script error.

With Regards
Bharath
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Mar 2015, 05:28 PM
Hello,

As per my knowledge there are multiple reason for this.
So could you please provide your grid code including update panel?

Thanks,
Jayesh Goyani
0
bharath
Top achievements
Rank 1
answered on 09 Apr 2015, 02:21 PM

HI Jayesh Goyani,

         i need to create dynamic radgrid with DropdownBox and checkBox . After getting the datasourse i need to check values of corresponding columns and need to do check or uncheck and selected item for dropdown.

  After pageload with the above i need to change the dropdownbox values and checkbox chek or uncheck.

  after i have to saved the latest values of radgrid by Button click event which is out side of grid.

   can you guide on this and create a sample page.

 

/Bharath

 

 

Tags
Grid
Asked by
Mattia
Top achievements
Rank 1
Answers by
Mattia
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Mira
Telerik team
bharath
Top achievements
Rank 1
Share this question
or