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

[Solved] Dynamically change the PushButton in a RadGrid

2 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 19 Jun 2009, 05:37 PM
I currently have a RadGrid that has two PushButtons... 
<telerik:GridButtonColumn CommandName="Complete_Select" ConfirmDialogType="RadWindow" 
                                                Text="Complete" UniqueName="completeSelect" CommandArgument="ID" AutoPostBackOnFilter="True" 
                                                ButtonType="PushButton" ButtonCssClass="btn" ItemStyle-Font-Bold="True">  
                                            </telerik:GridButtonColumn> 
                                            <telerik:GridButtonColumn CommandName="Split_Select" ConfirmDialogType="RadWindow" 
                                                Text="Input to Appraisal" UniqueName="splitSelect" CommandArgument="ID" AutoPostBackOnFilter="True" 
                                                HeaderText="Appraisal Form" ButtonType="PushButton" ButtonCssClass="btn" ItemStyle-Font-Bold="True">  
                                            </telerik:GridButtonColumn> 
 

Based on the "OnItemCommand" I run some codeBehind.
What I would like to do is make the PushButtons for that row disappear and replace them with text once the "completeSelect" has been pressed.
Any help would be appreciated.

 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jun 2009, 04:44 AM
Hi Tom,

Try the following code snippet and see whether it is working as you expected.

CS:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == "Complete_Select"
    { 
        ((e.Item as GridDataItem)["completeSelect"].Controls[0] as Button).Visible = false;        
        foreach(GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (item["completeSelect"].Controls[0].Visible == false
            { 
                Label lbl = new Label(); 
                lbl.Text = "Complete"
                item["completeSelect"].Controls.Add(lbl); 
            } 
        } 
    } 

Shinu
0
Tom
Top achievements
Rank 1
answered on 22 Jun 2009, 05:25 PM
Thanks Shinu!
I actually had to modify it a little to get it to work.
I added this to get the page to refresh correctly.
    protected void RadGrid2_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid2.MasterTableView.Items)  
        {  
 
            if (item.Cells[5].Text == "C")  
            {  
                item["completeSelect"].Controls[0].Visible = false;  
                Label lbl = new Label();  
                lbl.Text = "Complete";  
                item["completeSelect"].Controls.Add(lbl);  
            }  
        }  
 
    }  
 
Because I am reading from and writing to a database I needed to add this or else the event always came back true.

Many thanks!!

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