1

I am working in asp.net using the gridview control. I have a button column that I create dynamically as such:

            ButtonField bfSelect = new ButtonField();
            bfSelect.HeaderText = "View";
            bfSelect.ButtonType = ButtonType.Link;
            bfSelect.CommandName = "View";
            bfSelect.Text = "View";

            grdAttachments.Columns.Add(bfSelect);

The text on the button is the same for every row. I was wondering if there was any way to have the text be different for different rows depending on a condition. When I try to look at the text property of a particular row it is blank, if I try to set it, it does not change.

Thanks in advance.

Bob

Bob Avallone
  • 979
  • 7
  • 20
  • 36

3 Answers3

1

in the RowDataBound event you can check the current row. For example:

String text = ((Label)e.Row.FindControl("aLabel")).Text;
if(text == "Yes")
{
    ((LinkButton)e.Row.FindControl("bfSelect").Text = "Good to go!";
} 

For this you also need to set the ID of the button to bfSelect.

Grz, Kris.

Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61
  • I'm trying this exact code, and when I try to enter .Text, the option box does not pop up. If I write it out anyway, the error it gives me is 'System.Web.UI.Control' does not contain a definition for 'Text'. – Jared May 04 '12 at 15:20
0

The Best is edit in Javascript : [If you not use ajax.]

$("#GridView1 tr td a").html("Custom_Delete_Text");
$("#GridView1 tr td a").addClass("another class you wish");

S.A.Parkhid
  • 2,772
  • 6
  • 28
  • 58
0

There are a few ways to do this, off the top of my head I suggest you change the value in the RowDataBind event.

This is hand typed, so there might be typos..

protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row .RowType == DataControlRowType .DataRow )
  {
    Button button = (Button)e.Row.Cells[0].Controls[0];
    button.Text = "Your New Value";
  }
}
Zachary
  • 6,522
  • 22
  • 34