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

[Solved] Binding dynamic event handling on server side code

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Viswanathan
Top achievements
Rank 1
Viswanathan asked on 29 Jul 2009, 06:53 PM
Hi,

I've a <Linkbutton> embedded in RAD Grid control. I want to map the eventhandler dynamically. 

Here is my code. What i'm trying to do here opening a pop-up dialog on clicking the link button, but, unfortunately the event for the control is not biding to the control!

protected void grd_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) 
        { 
            try 
            { 
                if (e.Item is GridDataItem) 
                { 
                    GridDataItem grdItem = (GridDataItem)e.Item; 
 
                    LinkButton lnk1 = e.Item.FindControl("link1"as LinkButton; 
                    Label lbl1 = e.Item.FindControl("label1"as Label; 
                    lnk1.CommandArgument = lbl1.Text; 
                    lnk1.Click += new EventHandler(lnk1_Click); 
                } 
            } 
       } 

       protected void lnk1_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                LinkButton lnkButton = sender as LinkButton; 
                string argument = lnkButton.CommandArgument; 
 
              Page.ClientScript.RegisterClientScriptBlock(string.Empty.GetType(), "showpopup"
                    "OpenPopupPage('lnkbutton');"true); 
            } 
            catch (Exception ex) 
            { 
                lblErrorMessage.Text = ex.Message; 
            } 
        } 
 

Let me know what mistake i am doing here

Thanks in advance
Viswa

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Jul 2009, 06:49 AM
Hi Viswanathan,

You need to use ItemCreated instead. ItemDataBound will be raised only during data-binding and if the grid is recreated from ViewState you will not get this event.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Viswanathan
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or