自定义编辑删除选择GridView中的链接

时间:2012-01-26 13:19:15

标签: asp.net visual-web-developer

我想将GridView中的编辑删除选择链接替换为图标 我怎么能以编程方式做到这一点?

1 个答案:

答案 0 :(得分:4)

您可能会有所不同(取决于您有编辑,删除,选择按钮的位置)。我添加了一个gridview,并在第一列中有Buttons。然后我在RowDataBound事件中添加了这个:

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' />";

        }
    }
祝你好运!