Programmatically add linkbutton to gridview in asp.net with c#.net

Check this code snippet

int rowIndex;
        for(rowIndex = 0; rowIndex < myGrdView.Rows.Count; rowIndex++)
        {
            LinkButton ObjlnkBtn = new LinkButton();
            ObjlnkBtn.Text = "Click";
            //Let myGrdView.Rows[i].Cells[0].Text contains the item ID
            ObjlnkBtn.PostBackUrl = "EditPage.aspx?ID=" + myGrdView.Rows[i].Cells[0].Text;
            //Add Link button to the fifth column of each row in the GridView
            myGrdView.Rows[i].Cells[5].Controls.Add(ObjlnkBtn);
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.