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

RadGrid Control Values Blank on Insert

2 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 01 Mar 2012, 07:03 PM
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

<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);
                
           }
}
 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Mar 2012, 06:38 AM
Hello,

I cannot reproduce the issue at my end. Here is the sample code that I tried which worked as expected.
C#:
protected void grid_ItemCommand(object sender, GridCommandEventArgs e)
{
 if (e.CommandName == "PerformInsert")
 {
   GridEditFormInsertItem itm = (GridEditFormInsertItem)e.Item;
   RadNumericTextBox txt= (RadNumericTextBox)itm.FindControl("newDeviceIP_edit");
   string val=txt.Text;
 }
}

-Shinu.
0
William
Top achievements
Rank 1
answered on 02 Mar 2012, 05:11 PM
Never mind I'm stupid. I was accidentally clearing those values in a prior event call. Thanks for your help. 
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
William
Top achievements
Rank 1
Share this question
or