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

Update text of label in CommandItemTemplate

2 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris LaFrancis
Top achievements
Rank 1
Chris LaFrancis asked on 19 Apr 2010, 08:59 PM
I have a grid that has 2 labels in the CommandItemTemplate. I also have a RadWindow that I use for a user to set the upper and lower limit values to use on a couple of columns in the grid. When the RadWindow closes I want to take teh values from that window and update the text int he CommandItemTemplate.
My values are returning from the RadWindow correctly and they are being put into 2 variables - lowerLimit and upperLimit.
The label fields on the CommandItemTemplate are:

<

 

asp:Label ID="lblLLimit" runat="server" Text="= over 85%"></asp:Label>

 

<

 

asp:Label ID="lblULimit" runat="server" Text="= over 100%"></asp:Label>

 

How can I update the labels text to display the values returned from the RadWindow programatically?
Thank you very much for your help.
Chris

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 20 Apr 2010, 09:45 AM
Hello Chris,

You can attach OnClientClose event to RadWindow and get the parameters passed from the window. Then invoke an ajaxRequest() and pass the values to code behind.

<script type="text/javascript"
    function ClientClose() { 
        var lowerLimit = 1; // Get the parameters
        var upperLi8mt = 10; // Get the parameters
        var myValues = new Array(); 
        myValues[0] = lowerLimit; 
        myValues[1] = upperLi8mt; 
        var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>"); 
        ajaxManager.ajaxRequest(myValues); // invoke ajaxRequest explicitly
  } 
</script> 

In the RadAjaxManager1_AjaxRequest event, access the Lables placed in the CommandItemTemplate and set the Text according to the values passed.
CS:
 
    protected void RadAjaxManager1_AjaxRequest1(object sender, AjaxRequestEventArgs e) 
    { 
        string values = e.Argument;  // Get the argument passed
        string[] array; 
        array = values.Split(','); 
        GridCommandItem cmditem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0]; 
        { 
            Label lb1 = (Label)cmditem.FindControl("Label1"); 
            lb1.Text = array[0];  
 
            Label lb2 = (Label)cmditem.FindControl("Label2"); 
            lb2.Text = array[1]; 
        }  
    } 

Also set the AjaxSettings accordingly.
ASPX:
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest1"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManager> 


Regards,
Shinu.



0
Chris LaFrancis
Top achievements
Rank 1
answered on 20 Apr 2010, 04:32 PM
That worked great!!!
Thank you very much for your help with this.

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