I have a RadGrid that uses TemplateFields to add/edit data. I use the ItemCommand event to access the Insert command and insert data. I have no issues finding the control in that event, but none of the controls I access have any data.
For example: if I add a new record to the Grid, fill out the text box and click insert; the control is found in the code behind, but the text field is empty, even though I filled out text box. I'm stumped as to why this happens. Below is my code.
ASPX
C#
For example: if I add a new record to the Grid, fill out the text box and click insert; the control is found in the code behind, but the text field is empty, even though I filled out text box. I'm stumped as to why this happens. Below is my code.
ASPX
<telerik:RadGrid ID="ipAddressGridNewDevice" runat="server" AutoGenerateColumns="false" Width="250" OnLoad="ipAddressGridNewDevice_OnLoad" OnItemCommand="ipAddressGridNewDevice_ItemCommand" AutoGenerateDeleteColumn="true" AutoGenerateEditColumn="true"> <MasterTableView CommandItemDisplay="Top"> <Columns> <telerik:GridTemplateColumn HeaderText="IP Address"> <ItemTemplate> <asp:Label ID="newDeviceIP" runat="server" Text='<%# Bind("IPAddress") %>' /> </ItemTemplate> <EditItemTemplate> <p> <telerik:RadTextBox ID="newDeviceIP_edit" runat="server" /> </p> </EditItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Attenuation"> <ItemTemplate> <asp:Label ID="newDeviceAtten" runat="server" Text='<%# Bind("Attenuation") %>' /> </ItemTemplate> <EditItemTemplate> <p> <telerik:RadNumericTextBox ID="newDeviceAtten_edit" runat="server" ShowSpinButtons="true" Width="50px" MinValue="0" Value="0"> <NumberFormat DecimalDigits="0" /> </telerik:RadNumericTextBox> </p> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="true" /> </MasterTableView></telerik:RadGrid>C#
protected void ipAddressGridNewDevice_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "PerformInsert") { GridEditFormInsertItem editedItem = e.Item as GridEditFormInsertItem; RadTextBox newDeviceIP_edit = (RadTextBox)editedItem.FindControl("newDeviceIP_edit"); RadNumericTextBox newDeviceAtten_edit = (RadNumericTextBox)editedItem.FindControl("newDeviceAtten_edit"); addIPAddressNewDevice(deviceIPTable, newDeviceIP_edit.Text, (Int32)newDeviceAtten_edit.Value); }}