Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

edit buttonfield text in gridview 1

Status
Not open for further replies.

TwoOdd

Programmer
Sep 10, 2003
196
CL
I have a buttonfield in a gridview that I want to change the text dynamically when the row is created. Any help would be appreciated. If more information is required to answer the question, please let me know.

Thanks in advance

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
Not exactly sure what you are asking. But if you want to change something while the row is being created, use the rowcreated event of the gridview.
 
I have a gridview with a button that reads "Notes" and if there are notes for that given record, I would like to change the text on the button to read "Notes*". So some rows will have a button that reads "Notes" while other rows will have the button read "Notes*". The problem I'm having is I don't know how to reference the button in the gridview. I'm already using the rowcreated event, but what is the syntax for referencing a buttonfield and more specifically changing the text on the button?

Thanks

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
here's the pertinent html code:

Code:
<asp:GridView ID="MyGrid" runat="server">
<columns>
<asp:BoundField DataField="fld_CountNotes">
<asp:CommandField ButtonType="Button" EditText="Notes" ShowEditButton="True">
</columns>
</asp:GridView>

In the RowDataBound event, I would like to do something like this:

Code:
If e.Row.RowType = DataControlRowType.DataRow Then
   If e.Row.Cells(0) > 0 Then
      e.Row.Cells(1).Button.EditText = "Notes*"
   Else
      e.Row.Cells(1).Button.EditText = "Notes"
   End If
End If

My problem is that I don't know how to reference the 'EditText' attribute of the commandfield button.

Any help on this would be appreciated.

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
Thanks. Had to do a little converting to VB, but was able to make it work. Here is the code for those who need it in VB (this is in the RowDataBound event of the gridview):

Code:
Dim MyButton as Button
If e.Row.RowType = DataControlRowType.DataRow Then

MyButton = e.Row.Cells(1).Controls(0)
   If e.Row.Cells(0) > 0 Then
      MyButton.Text = "Notes*"
   Else
      MyButton.Text = "Notes"
   End If
End If

My understanding is that "Controls(0)" is the Edit Button in the command field - using 2 or 4 instead of 0 supposedly accesses the delete or select buttons. Haven't tested that so use at your own risk.

Thanks again jbenson001 for the link.

TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top