techBeginner
techBeginner

Reputation: 3850

get server side event for image click inside a Telerik:RadGrid control

I am new to Rad controls..

I have an image inside a column of RadGrid..when this image is clicked, I want to update another AjaxPanel..but I am not able to find the event where I can do this..

I tried like this..

...
    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:ImageButton ID="ImgEdit" runat="server" 
                             ImageUrl="Images/edit.png" 
                             OnClick="EditImage_Click" />
        </ItemTemplate>
    </telerik:GridTemplateColumn>
...
....
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="ImgEdit">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
....

and

    protected void EditImage_Click(object sender, EventArgs e)
    {

    }

I also tried below code in Page_Load..

((ImageButton)(RadGrid1.FindControl("ImgEdit"))).Click += 
                               new ImageClickEventHandler(EditImage_Click);

but nothing seems to be working..

Please HELP...

Upvotes: 0

Views: 3134

Answers (2)

Ravi Gadag
Ravi Gadag

Reputation: 15861

you missed CommandName property, ItemCommand will occur only if "Buttons within a GridView control can also invoke some of the built-in functionality of the control. To perform one of these operations, set the CommandName property of a button"

<telerik:GridTemplateColumn UniqueName="TempCol" >  
                         <ItemTemplate>  
                             <asp:ImageButton ID="ImageButton1" runat="server" CommandName="DoEdit" />  
                         </ItemTemplate>  
                        </telerik:GridTemplateColumn>

Event handler

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "DoEdit") 
            { 
                //dosomething

            } 

        } 

Upvotes: 1

Gaurav Agrawal
Gaurav Agrawal

Reputation: 4431

Don't call EditImage_Click event of a imagebutton you can gave a command name to this imagebuttom and call grid row command event and use this row command event instead of EditImage_Click event

Upvotes: 1

Related Questions