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

DataGrid onDataItemBound unable to change ButtonColumn Text

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 08 Sep 2008, 10:08 PM
Hi,

I have datagrid with GridButtonColumn.  I would like to change the text on ItemDataBound.  However, it doesn't work.

                <telerik:RadGrid ID="dgDFR" runat="server" AutoGenerateColumns="False" GridLines="None" EnableEmbeddedSkins="false" Skin="Windows" OnItemDataBound="dgDFR_ItemDataBound">  
                    <MasterTableView CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" Width="900px" 
                        Dir="LTR" Frame="Border" TableLayout="Auto" DataKeyNames="ID" AlternatingItemStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">  
                        <NoRecordsTemplate>There is no data product for you at this time.</NoRecordsTemplate> 
                        <Columns> 
                                <telerik:GridButtonColumn UniqueName="Action" HeaderText="Action"></telerik:GridButtonColumn> 
                        </Columns> 
                    </MasterTableView> 
                </telerik:RadGrid>              
 

        protected void dgDFR_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
        {  
                if (e.Item is GridDataItem)  
                {  
                    GridDataItem item = (GridDataItem)e.Item;  
                        GridButtonColumn gbtnCol = item.OwnerTableView.Columns.FindByUniqueName("Action") as GridButtonColumn;  
                            gbtnCol.Text = "Resume";  
                            gbtnCol.DataTextFormatString = "Resume";  
                }  
        }  
 


Please let me know what the problem is with my code provided above. 

Chris

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Sep 2008, 04:41 AM
Hi Chris,

Try accessing the button for the GridButtonColumn in the ItemCreated event and set the text for the button as shown below.

CS:
 protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            LinkButton lnkbtn = (LinkButton)item["Action"].Controls[0]; 
            lnkbtn.Text = "Resume"
        } 
   } 


Thanks
Shinu.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or