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

Fire button event in RadGrid

4 Answers 336 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 13 Mar 2010, 09:07 PM
Hey!

I have a GridTemplateColumn where I define a TextBox and a Button in the EditItemTemplate property. How is it possible to fire the onClick event of the button.

I have tried the following:
<asp:ImageButton ID="Button" runat="server" ImageUrl="~/Resources/key.png" OnClick="Button_Click" />

... but this doesn't work I always get the following compilation error "...does not contain a definition for 'Button_Click' and no extension method ... (are you missing a using directive or an assembly reference?)".

I don't know what I made wrong - can anybody help me?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Mar 2010, 06:09 AM
Hello Simon,

Have you added the Button_Click event on server code?

C#:

 
    protected void Button_Click(object sender, EventArgs e)  
    {  
        // Your code  
    }  

Another option is setting the CommandName for button and check for the CommandName in ItemCommand event.

ASPX:

 
<telerik:GridTemplateColumn>  
    <EditItemTemplate>  
        <asp:ImageButton ID="ImageButton1" runat="server" CommandName="custom" />  
    </EditItemTemplate>  
</telerik:GridTemplateColumn> 

C#:

 
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "custom")  
        {  
            // Your code  
        }      
    } 


-Shinu.
0
Simon
Top achievements
Rank 1
answered on 15 Mar 2010, 08:41 AM
Hello Shinu!

Thank you very much for your help.

Now I have found what I made wrong. I have added the Butten_Click event on server code but I choosed the wrong access modifier for the methode - I haven't seen that, this was my mistake. Therefore I always get the error on compilation time.

Now everything works. Thank you!

0
Kokila
Top achievements
Rank 1
answered on 17 Mar 2016, 10:01 AM

I am having a button on the header. On button click it should get the rows which has checkbox selected. i couldn't get the selected rows. because when there is postback the grid rebind the initial data.

Please help

Thanks in Advance

0
Kostadin
Telerik team
answered on 22 Mar 2016, 06:57 AM
Hi Kokila,

I prepared a small sample where I get the selected items on the server. Please check out the attached sample and let me know how it differs form your real setup?

Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Simon
Top achievements
Rank 1
Kokila
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or