Search code examples
asp.netvisual-web-developer

Custom Edit Delete Select links in GridView


I want to replace the Edit Delete Select links in GridView to be icons.
How can I do this programatically?


Solution

  • It might be different for you (depending where you have the Edit, Delete, Select buttons). I added a gridview, and have the Buttons in the first Column. Then I added this in the RowDataBound event:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow) {
    
                LinkButton lbEdit = (LinkButton)e.Row.Cells[0].Controls[0];
                lbEdit.Text = "<img src='https://www.google.com/logos/classicplus.png' />";
                //There is a literal in between
                LinkButton lbDelete = (LinkButton)e.Row.Cells[0].Controls[2];
                lbDelete.Text = "<img src='https://www.google.com/logos/classicplus.png' />";
                //There is a literal in between
                LinkButton lbSelect = (LinkButton)e.Row.Cells[0].Controls[4];
                lbSelect.Text = "<img src='https://www.google.com/logos/classicplus.png' />";
    
            }
        }
    

    Good luck!