I'm using RadGrid Form Templates as below;
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table id="tblEditForm" cellpadding="2" cellspacing="2" width="100%" border="2px"
class="tblEditForm">
<tr>
<th>
Server Name:
</th>
<td>
<asp:TextBox ID="tbServerName" runat="server" Text='<%# Bind("ServerName") %>' CssClass="tbServerName">
</asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<div style="text-align: left; padding-left: 10px;display: inline; width: 50%">
<asp:LinkButton ID="lbTestConnection" runat="server" Text="Test Connection" CommandName="TestConnection" />
(It may take up to 15 seconds.)
<br />
</div>
<asp:Label ID="lblTestConnectionResult" runat="server" CssClass="testConnectionResult"></asp:Label>
<div style="text-align: right; padding-right: 10px;display: inline; float: right;">
<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
</div>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
When the Update link button is clicked on my RadGrid, the Edit Form is displayed. Then I click the Test Connection link button and ItemCommand event is raised.
public void OnRadGridItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "TestConnection")
{
var gridEditFormItem = e.Item as GridEditFormItem;
if (gridEditFormItem == null)
throw new ApplicationException("gridEditFormItem is null");
var serverNameTextBox = gridEditFormItem.FindControl("tbServerName") as TextBox;
}
}
The problem is that the gridEditFormItem variable is null at this stage so I can't figure out the value of the server name text box for example.
How to get the value of the textbox on RadGrid ItemCommand event handler?
If I click the default insert link button of the RadGrid instead, the gridEditFormItem has value so I can simply find the value of my textbox there.
Please help.
Thanks,
I fixed it :)
When Inserting, the e.Item is a GridEditFormItem. When Updating, the e.Item is a GridDataItem!