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

[Solved] Modify a control in a TemplateColumn when in Edit Mode.

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hk proj
Top achievements
Rank 1
hk proj asked on 06 Aug 2009, 08:41 AM
Hi, I'm having troubles using RadGrid.
I am using the following declaration to create a TemplateColumn:
<rad:GridTemplateColumn UniqueName="masterpage" HeaderText="<%$ Resources:Grids,Portals_MasterPage %>" > 
    <ItemTemplate><asp:Label ID="labelMasterPage" runat="server" Text='<%# GetFileName(Eval("masterpagefile").ToString()) %>' /></ItemTemplate>  
    <EditItemTemplate> 
        <asp:DropDownList ID="dropDownFileNames" runat="server" DataSource='<%# GetMasterPages(Eval("homedirectory").ToString()) %>' /> 
    </EditItemTemplate> 
</rad:GridTemplateColumn> 
I want to modify the SelectedValue property of the DropDownList in the EditItemTemplate when the row goes in Edit Mode.
But the problem is that whenever I search the dropdownlist in a GridEditableItem (inside EditCommand event, for example), I receive the 'NullReferenceException'.
How can I solve this problem?
Thanks in advance.
PS: I'm using RadControl 3.5 in ASP.NET 3.5.

1 Answer, 1 is accepted

Sort by
0
hk proj
Top achievements
Rank 1
answered on 06 Aug 2009, 09:01 AM
Ok, solved.
I used the following code:
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            var item = e.Item as GridEditableItem;  
            (item["masterpage"].FindControl("dropDownFileNames") as DropDownList).SelectedValue = item.GetDataKeyValue("masterpagefile").ToString();  
        } 
Hope it helps.
Bye.
Tags
Grid
Asked by
hk proj
Top achievements
Rank 1
Answers by
hk proj
Top achievements
Rank 1
Share this question
or