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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use text and eval field in Button Text

Status
Not open for further replies.

gtjr92

Programmer
May 26, 2004
96
I want to have a bound button that will show some text and the row value on the button. It would say click here to view The field name.
I tried a few variations of the below code with + sumbol and the &.
I am using .net 2 but i guess it would be at least similar to .net 1.1 I am doing this in an item template field, but it could be a bound button as well. I am sure code is the same.
Code:
<asp:Button runat="server" Text="Click here to change the Name for" + " '<%#(Eval("ClassName")) %>'" />
 
yes class name is the name of the colum I should have clarified that.
 
Another quick question.. Is the button in a template column also, or just a standard button field?
 
It is a button field within a column. I tried this with a template and without. So it really does not matter either will work for me.
 
OK, what I did was creat a gridview, bound some columns, put a button filed on it, and one template column with a label that is bound that holds a value you want to dispaly as text on the button:

Code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim btn As New Button
            Dim lbl As New Label
            ''Change the cell index to match your gridview.
            btn = e.Row.Cells(0).Controls(0)
            lbl = e.Row.Cells(6).FindControl("label1")

            btn.Text = "Click here to change the Name for " + lbl.Text

        End If
    End Sub
Hope this helps you ...
Jim
 
i'll check it out. I knew how to do that, but i figured there was an easier way with less code.
Looks like I will need to add a for each row loop to this code too otherwise I think I will on get the data from one column.
thanks.
 
oh yeah duh I see it now I just skimmed the code earlier.
Thanks again. I'll check it out tommorow
 
I got it figured out I knew there had to be an easier way

Code:
<asp:Button runat="server" [COLOR=red]Text='<%# Eval("ClassName",  "Click Here to Edit Assignments for" + " " + Eval("ClassName")) %>'[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top