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

Event not working in Telerik.Web.UI.RadGrid

3 Answers 115 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dai Thanh
Top achievements
Rank 1
Dai Thanh asked on 26 Jan 2011, 11:42 AM
Hi,

I have problem, i create RadGrid by code and registry event ItemDataBound,

 void dataGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
           if (e.Item is GridFooterItem)
            {
                GridFooterItem footer = (GridFooterItem)e.Item;
              
                    string interName = "name";
                    footer[interName].Controls.Add(new LiteralControl("<b>" + GetLabel("Goto", "Go to") + " </b>"));
                    LinkButton lbtIndex = new LinkButton();
                    lbtIndex .Text ="1";
                    lbtIndex .ID = "lbl1";
                    lbtIndex .Click += new EventHandler(lbtIndex _click);
                    footer[interName].Controls.Add(lbtIndex );
              
            }
        }
        void lbtIndex _click(object obj, EventArgs e)
        {
         //to do
       }

But when i click LinkButton 1 (lbtIndex _click), the event of button dont fire.


 

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 31 Jan 2011, 10:20 PM
Hello Dai Thanh,

You have to add the LinkButton in the ItemCreated handler, otherwise it will disappear when you click it.
Distinguishing the major differences between ItemCreated and ItemDataBound events

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Dai Thanh
Top achievements
Rank 1
answered on 08 Feb 2011, 05:12 AM
Hello Daniel

I added the LinkButton in the ItemCreated handler but lbtPageNumber_Click not working, just fire event linkButtonBack_Click .

 void dataGrid_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridPagerItem)
            {
                GridPagerItem pagerItem = (GridPagerItem)e.Item;
                pagerItem.PagerContentCell.Controls.Clear();
       
                LinkButton linkButtonBack = new LinkButton();
                linkButtonBack.ID = "lbtBack";
                linkButtonBack.Text = "Back";
                linkButtonBack.Click += new EventHandler(linkButtonBack_Click);
                linkButtonBack.Font.Underline = false;
                linkButtonBack.Attributes.Add("style","margin: 0px 5px 0px 15px");
                linkButtonBack.CommandName = "page";
                linkButtonBack.CommandArgument = "1";
                pagerItem.PagerContentCell.Controls.Add(linkButtonBack);
           
               //~~~Add Number Paging ~~~//
            
                int i = 0;
                while (i < this.totalPage)
                {
                    i += 1;
                    LinkButton lbtPageNumber = new LinkButton();
                    lbtPageNumber.ID = "lbtPageNumber" + i;
                    lbtPageNumber.Font.Underline = false;
                    lbtPageNumber.Text = i.ToString();
                    lbtPageNumber.Attributes.Add("style", "margin: 0px 2px 0px 2px");
                    lbtPageNumber.CommandName = "page";
                    lbtPageNumber.CommandArgument =i.ToString ();
                    lbtPageNumber.Font.Underline = false;
                    lbtPageNumber.Click += new EventHandler(lbtPageNumber_Click);
                     pagerItem.PagerContentCell.Controls.Add(lbtPageNumber);

                }
              
            }
        }

 void linkButtonBack_Click(object sender, EventArgs e)
        {
          //to do
        }
        void lbtPageNumber_Click(object sender, EventArgs e)
        {
          //to do
        }
0
Daniel
Telerik team
answered on 11 Feb 2011, 01:14 PM
Hello Dai,

  Your code works properly on my end. Please test the attached demo and let me know whether the link buttons behave as expected when you run it locally.

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
General Discussions
Asked by
Dai Thanh
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Dai Thanh
Top achievements
Rank 1
Share this question
or