Fire button event in RadGrid

5 posts, 0 answers
  1. Simon
    Simon avatar
    5 posts
    Member since:
    Sep 2012

    Posted 13 Mar 2010 Link to this post

    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?

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Mar 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Simon
    Simon avatar
    5 posts
    Member since:
    Sep 2012

    Posted 15 Mar 2010 Link to this post

    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!

  5. Kokila
    Kokila avatar
    1 posts
    Member since:
    Mar 2016

    Posted 17 Mar in reply to Shinu Link to this post

    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

  6. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 22 Mar Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017