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

[Solved] Changing Link Button Column Text Based on Value of Field

3 Answers 493 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raventhorn
Top achievements
Rank 2
Raventhorn asked on 14 Jul 2009, 04:37 AM
I have a field in my RadAjaxGrid where it will display a Link styled button with the text "Enable" or "Disable". I need to set this value on a per row basis based on the value of a DataBound field called "Active". How can I do this most efficiently?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jul 2009, 06:07 AM
Hi,

You may try out the logic used in the following help article to achieve the desired scenario.
Conditional image display in GridButtonColumn/GridTemplateColumn

Thanks
Shinu
0
Raventhorn
Top achievements
Rank 2
answered on 14 Jul 2009, 03:53 PM
How though in code would I get the value of a different cell in the row? The status of the row (Active or not) is a hidden field in the row. I did that intentionally so I could quickly make the decision on a row by row basis.
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Jul 2009, 05:16 AM
Hello,

You can set the Active field as one of the DataKeyNames od the grid and then retrieve the datakeyvalue using code and based on the value set the text of the link button:
aspx:
 <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" 
 OnItemDataBound="RadGrid1_ItemDataBound">  
          <MasterTableView DataKeyNames="Active">  

c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item.GetDataKeyValue("Active").ToString() == "active"
            { 
                ((LinkButton)item["ButtonColumnUniqueName"].Controls[0]).Text = "Enable"
            } 
            else 
            { 
                ((LinkButton)item["ButtonColumnUniqueName"].Controls[0]).Text = "Disable"
            } 
        } 
    } 

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