This is a migrated thread and some comments may be shown as answers.

[Solved] Change caption in GridButtonColumn

2 Answers 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik Hansen
Top achievements
Rank 1
Erik Hansen asked on 14 Jan 2010, 01:23 PM

Hi
I'm trying to change the caption/text on a GridButtonColumn, by code.
What i want is that the text on the PushButton is dependent on the value of a field.
The result is that I don’t see the push button, but only a text.
Can anybody tell me what I do wrong?

Thanks
Erik


aspx
<telerik:GridButtonColumn ButtonType="PushButton" text="Create" 
         UniqueName="versionFunction" HeaderText="Function"
    <HeaderStyle Width="100px"></HeaderStyle> 
</telerik:GridButtonColumn> 

C#
 protected void Grid_Versioner_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            switch (dataItem["Status"].Text) 
            { 
                case "Created"
                    dataItem["versionFunction"].Text = "Execute"
                    break
                case "Executing"
                    dataItem["versionFunction"].Text = "Executeing"
                    break
            } 
        } 
    } 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Jan 2010, 01:54 PM
Hello Eric,

Inorder to change the Button text from code, you have to access the button and change its text as shown below:
c#:
((Button)dataItem["versionFunction"].Controls[0]).Text = "Execute";  

Thanks
Princy.
0
Erik Hansen
Top achievements
Rank 1
answered on 14 Jan 2010, 02:16 PM

Thanks, that was a quick response

Tags
Grid
Asked by
Erik Hansen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Erik Hansen
Top achievements
Rank 1
Share this question
or