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

[Solved] Localization of FormTemplate

3 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
François
Top achievements
Rank 1
François asked on 05 Jun 2008, 07:29 AM
Hi,

I want to know how set a text for Label, Literal, ... in a <FormTemplate> of a RadGrid.

My project uses a GlobalResource and a function which loop all controls (and subcontrols, ... with recursivity) and change text of control if resource exists. But when I try to find controls in a GridEditableItem, I don't find my Label. Here an example :

<FormTemplate> 
<b>User Details</b> 
                        <table id="tblEditForm"
                            <tr> 
                                <td><asp:Label ID="lblLangLastname" Text="<$>" runat="server"></asp:Label> : </td> 
                                <td><asp:TextBox ID="TextBox12" runat="server" Text='<%#Bind("usr_lastname")%>' /></td
                            </tr> 
                        </table> 
</FormTemplate> 

protected void gridUsers_ItemCommand(object source, GridCommandEventArgs e) 
        if ((e.CommandName == RadGrid.InitInsertCommandName) || (e.CommandName==RadGrid.EditCommandName)) 
        { 
            SetTraductions("", ((GridEditableItem)e.Item)); 
        } 

Is there any method to modify texts of controls in a FormTemplate.
Thanks.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jun 2008, 04:38 AM
Hi,

Try accessing the controls in the FormTemplate in the ItemDataBound event as shown below.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem edititem = (GridEditableItem)e.Item; 
            Label lbl = (Label)edititem.FindControl("Label1"); 
            lbl.Text = "MyCustomText"
            TextBox txtbx = (TextBox)edititem.FindControl("TextBox1"); 
 
        } 
         
    } 


Thanks
Shinu.
0
François
Top achievements
Rank 1
answered on 06 Jun 2008, 06:50 AM
Perfect !

Thanks a lot.
Fran
0
Princy
Top achievements
Rank 2
answered on 11 Jun 2008, 11:24 AM
Hi Fran,

You can also use the PreRender event of  RadGrid to access the controls in a FormTemplate.

CS:
 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridEditFormItem edititem in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem))  
        {  
            if (edititem.IsInEditMode)  
            {  
                Label lbl = (Label)edititem.FindControl("Label1");  
                lbl.Text = "MyCustomText";  
                TextBox txtbx = (TextBox)edititem.FindControl("TextBox1");  
            }  
        }  
    } 


Thanks
Princy.
Tags
Grid
Asked by
François
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
François
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or