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

Calling grid and child events from clientside

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BRK
Top achievements
Rank 1
BRK asked on 10 May 2011, 11:04 AM
Hi Friends,

I want to display lots of data in RadGrid in which there will be some child controls in the grid which are having some events.
My point is here.. with this huge data if I call those events from server side it will definitely takes some time. I want a solution to
reduce the time using any client side techniques.
How to call events using Javascript client side techniques?
If anyone of you know help please help me in this connection.

Thanking you,
Bharath

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 May 2011, 11:37 AM
Hello Bharath,

You can attach the client events to the child controls either from aspx or from code behind. Here is the sample code.

From aspx:
<telerik:GridTemplateColumn UniqueName="TemplateCol">
     <ItemTemplate>
       <asp:Button ID="Btn1" runat="server" Text="Button1" OnClientClick="showAlert();" />
    </ItemTemplate>
 </
telerik:GridTemplateColumn>
Javascript:
function showAlert()
    {
        alert("Button Clicked");
    }

For attaching from server side, hook ItemCreated and try the following.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           Button btn = (Button)item.FindControl("Btn1");
           btn.Attributes.Add("onclick", "showalert(" + e.Item.ItemIndex +")");
       }
   }

Javascript:
function showalert(index)
    {
        alert(index);
    }

Thanks,
Princy.
Tags
Grid
Asked by
BRK
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or