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

RadGrid Edit FormTemplate control access

1 Answer 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 1
Grant asked on 19 Sep 2008, 10:51 PM
Hey,
I'm trying to use a RadGrid with inline editing via a custom template.  The scenario is complicated by the use of a special selection control we've built which pops up in a modal popup and allows the user to select the value for one of the fields that the RadGrid displays.  When the user selects a value, the control fires its ItemSelected event with event args that pass the data we need to display and save to the database.  The code-behind handles this event by updating the text of the LinkButton that serves as both the displayed text and as the modal popup trigger, as well as updating the text of a css-hidden textbox that holds the actual value to save to the database.
This worked great when we were using a regular ASP.NET GridView, but we needed to show hierarchical data in nested DetailsTable rows below it, so we invested in the RadGrid for this purpose.  Now, however, I can't seem to access the controls that need to be updated inside the Edit FormTemplate, and it seems like every single example anywhere on the net is only accessing it through the event args of events raised by the RadGrid itself.
Let me post some trimmed-down code so you can follow what I'm doing.
Here's the markup in question inside the RadGrid MasterTableView EditFormSettings:

<FormTemplate> 
    <asp:LinkButton ID="selectGLAccountLinkButton" runat="server"  
    CommandArgument='<%# Eval("GLAccountID") %>'  
    OnCommand="SelectGLAccountLinkButton_Command"
        <%# Eval("GLAccount.GLAccountNumber")%> 
    </asp:LinkButton> 
    <asp:TextBox ID="selectedGLAccountTextBox" runat="server" CssClass="hideButton" Text='<%# Eval("GLAccountID") %>'></asp:TextBox> 
</FormTemplate> 

The SelectGLAccountLinkButton_Command event handler triggers a modal popup with the selection control inside it.
When the user selects the item they desire, the modal popup closes and fires this event handler to update the display and underlying data, which was working with a standard ASP.NET GridView as written below:

protected void GLAccount_ItemSelected(object sender, ItemSelectionPage.ItemSelectedEventArgs e) 
    GridViewRow row = projectGridView.Rows[projectGridView.EditIndex]; 
    ((LinkButton)row.FindControl("selectGLAccountLinkButton")).Text = e.DisplayText; 
    ((LinkButton)row.FindControl("selectGLAccountLinkButton")).CommandArgument = e.ItemID.ToString(); 
    ((TextBox)row.FindControl("selectedGLAccountTextBox")).Text = e.ItemID.ToString(); 

The problem being that, from the above event handler (which is in the code-behind of the same page as the RadGrid) I can't find a way to access the controls in question like I would need to do above. 

I've set a breakpoint inside that method and wandered all through the intellisense on RadGrid1., but I suspect I'm just not looking in the "right" place.

Can anyone give me a hand?  Or is accessing the edit FormTemplate only possible inside a telerik event handler, in which case we'll have to abandon RadGrid and go some other route?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 23 Sep 2008, 09:03 AM
Hi Grant,

Thank you for the detailed explanation.

RadGrid exposes EditItems collection which holds the edited items in the grid and I believe you can access the first item in it for your particular case with single row editing. Thus you will be able to invoke the FindControl(id) method for the corresponding GridEditableItem in order to access the controls inside the edited item.

An important detail you need to have in mind when referencing the EditItems collection of the grid is outlined at the bottom section of this help topic.
 
Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Grant
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or