7

I would like to change the text of the autogenerated "select" column in an ASP.NET GridView control. The text needs to be changed to the value of a DataField.

I suspect that there is a very logical way to do this but I am missing it. I am able to add controls and data via the pre-render event but is there an easier better way?

5 Answers 5

7

Use the TemplateField and place into it buttons or linkbuttons with appropriate CommandName property: ButtonField.CommandName Property You may set this button text using DataBinder.Eval method.

Sign up to request clarification or add additional context in comments.

Comments

7

The easiest way I found to do this is after the calling DataBind() just before the gridview control is displayed.

        foreach (GridViewRow row in gvAgreementList.Rows)
        {
            LinkButton lb = (LinkButton) row.Cells[0].Controls[0];
            lb.Text = "Edit";
        }

2 Comments

thank you dear BMASolutions, i use this (2 line into loop) in my solution in event GridView_RowDataBound.
This is the most consistent way to do this when using a GridView CommandField. This let's you easily change the CommandField EditText for each row. gvwUnapprovedCommissions.DataSource = dsPending; gvwUnapprovedCommissions.DataBind(); if (GetCurrentUserRole().ToString() != "Admin") { // Change the command button text to View for all except Admin. foreach (GridViewRow row in gvwUnapprovedCommissions.Rows) { LinkButton lb = (LinkButton)row.Cells[0].Controls[0]; lb.Text = "View"; } }
7

after <column> write this:

<asp:CommandField ShowSelectButton="True" SelectText="Save" />

and remove AutoGenerateSelectButton="True" from Gridview attribute.

Comments

3

First remove auto generated select then go to GridView tasks.. top right Button of GridView and then click on commandfields -> Select then edit SelectText.

(Edited answer of ShaileshK with some changes)

Comments

2

Go to GridVIew tasks.. top right Button of GridView and then click on edit columns In selected fields section Click on select field. change the value of select text. done.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.