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

Grid - Perform insert when item inserted

1 Answer 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 24 Jul 2014, 06:51 PM

Hi,

I can't get the data on my EditForm, please help.

        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RadGrid1.MasterTableView.IsItemInserted = true;//so I can insert after load
                RadGrid1.Rebind();
            }
        }

        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {
                GridEditFormInsertItem f = (GridEditFormInsertItem)RadGrid1.MasterTableView.GetInsertItem();
                Person p = new Person();
                p.FirstName = (f.FindControl("FirstName") as TextBox).Text; //?? this control doesn't exist
            }
        }

        protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
        {
            GridEditFormInsertItem item = e.Item as GridEditFormInsertItem; //?? this is null
        }

        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = Conselors;//loads a List<Person>
        }

  <telerik:RadGrid ID="RadGrid1" runat="server"
                        AllowPaging="false" AllowSorting="false" AutoGenerateColumns="false"
                        AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"
                        ShowHeader="false"                       
                        OnItemCommand="RadGrid1_ItemCommand"
                        OnPreRender="RadGrid1_PreRender"
                        OnNeedDataSource="RadGrid1_NeedDataSource"
                        OnInsertCommand="RadGrid1_InsertCommand">
                        <MasterTableView DataKeyNames="PersonID" Width="50%" CommandItemDisplay="Bottom">
                            <CommandItemTemplate>
                                <telerik:RadButton ID="RadButtonInsert" runat="server" Text="Add" CommandName="PerformInsert">
                                    <Icon PrimaryIconCssClass="rbAdd" PrimaryIconLeft="4" PrimaryIconTop="3"></Icon>
                              </telerik:RadButton>
                            </CommandItemTemplate>
                            <CommandItemSettings />
                            <NoRecordsTemplate></NoRecordsTemplate>
                            <EditFormSettings>
                                <PopUpSettings Modal="true" />
                            </EditFormSettings>
                            <Columns>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                                </telerik:GridEditCommandColumn>

                                <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="FirstName" DataField="FirstName">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="LastName" HeaderText="LastName" DataField="LastName">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Telephone" HeaderText="Telephone" DataField="Telephone">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="Email" HeaderText="Email" DataField="Email">
                                </telerik:GridBoundColumn>

                                <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />

                            </Columns>
                            <EditFormSettings EditFormType="Template">
                                <FormTemplate>
                                    * Person Name (Salutation, First, Middle, Last and Suffix):<br />
                                    <telerik:RadComboBox ID="RadComboBox1" runat="server"
                                        EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
                                        OnItemsRequested="DropDownListCertHolderSalutation_ItemsRequested">
                                    </telerik:RadComboBox>

                                    <telerik:RadTextBox  Width="250px" ID="TextBoxAttorneyFirstName" Text='<%# Bind( "FirstName") %>' runat="server" TabIndex="8">
                                    </telerik:RadTextBox>
                                    <telerik:RadTextBox  Width="25px" ID="TextBoxAttorneyMiddleInitial" Text='<%# Bind( "MiddleInitial") %>' runat="server">
                                    </telerik:RadTextBox>
                                    <telerik:RadTextBox  Width="250px" ID="TextBoxAttorneyLastName" Text='<%# Bind( "LastName") %>' runat="server">
                                    </telerik:RadTextBox>

                                    <telerik:RadComboBox ID="RadComboBox2" runat="server"
                                        EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
                                        OnItemsRequested="DropDownListCertHolderSuffix_ItemsRequested">
                                    </telerik:RadComboBox>
                                    <br />
                                    Address:<br />
                                    <telerik:RadTextBox  Width="500px" ID="TextBoxAttorneyAddress1" Text='<%# Bind( "Address1") %>' runat="server">
                                    </telerik:RadTextBox>
                                    <br />
                                    <telerik:RadTextBox  Width="500px" ID="TextBoxAttorneyAddress2" Text='<%# Bind( "Address2") %>' runat="server">
                                    </telerik:RadTextBox>
                                    <br />
                                    Country:
                                            <telerik:RadComboBox ID="RadComboBox3" runat="server"
                                                EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true" AutoPostBack="true"
                                                OnItemsRequested="DropDownListCertHolderCountry_ItemsRequested"
                                                OnSelectedIndexChanged="DropDownListCertHolderCountry_SelectedIndexChanged">
                                            </telerik:RadComboBox>
                                    &nbsp State:
                                            <telerik:RadComboBox ID="RadComboBox4" runat="server"
                                                EnableLoadOnDemand="True" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
                                                OnItemsRequested="DropDownListCertHolderState_ItemsRequested">
                                            </telerik:RadComboBox>
                                    <telerik:RadTextBox ID="RadTextBox6" runat="server" Width="200px" Visible="false"></telerik:RadTextBox>
                                    &nbsp City:
                                                    <telerik:RadTextBox ID="RadTextBox7" runat="server" Width="250px"></telerik:RadTextBox>
                                    &nbsp Zip Code:
                                            <telerik:RadMaskedTextBox Width="50px" ID="RadMaskedTextBox1" runat="server" Mask="#####" TextMode="SingleLine">
                                            </telerik:RadMaskedTextBox>
                                    <br />
                                    Telephone:
                                            <telerik:RadMaskedTextBox Width="125px" ID="RadMaskedTextBox2" runat="server" Mask="(###) ###-####-####" TextMode="SingleLine">
                                            </telerik:RadMaskedTextBox>
                                    &nbsp Fax:               
                                            <telerik:RadMaskedTextBox Width="125px" ID="RadMaskedTextBox3" runat="server" Mask="(###) ###-####-####" TextMode="SingleLine">
                                            </telerik:RadMaskedTextBox>
                                    &nbsp
                                            Email Address:
                                                    <telerik:RadTextBox ID="RadTextBox8" runat="server" Width="250px"></telerik:RadTextBox>
                                    <br />
                                </FormTemplate>
                            </EditFormSettings>
                        </MasterTableView>
                    </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 25 Jul 2014, 03:20 AM
Hi Steve,

I see that you are using a Template edit form, but I don't see the Insert/Update and Cancel button. On click of the Insert button the OnInsertCommand event fires and you can access the entered values there as follows:

C#:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
  GridEditFormInsertItem item = e.Item as GridEditFormInsertItem;
 //Access the RadTextBox in editrform
  RadTextBox txtFirstName = (RadTextBox)item.FindControl("TextBoxAttorneyFirstName");
  string firstName = txtFirstName.Text;
}

Thanks,
Princy
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or