Sir/Madam,
I am going to develop a insert command by clicking Add to display the RadTextbox as InsertItem Templates and click Add New Record after inputting all the datas INside the RadGrid
But when it goes into the testing, it is found that Getting the Items cannot be done and always show null
thw following is my code , please answer
protected void btnAddRecord_grdFlex_performInsert(object sender, EventArgs e)
{
RadButton butt = sender as RadButton;
foreach (GridDataItem dataItem in grdFlex.MasterTableView.Items)
{
RadTextBox textBox1 = (RadTextBox)(dataItem["Company"].FindControl("txtSubcomName"));
RadTextBox textBox2 = (RadTextBox)(dataItem["FlexAcctCode"].FindControl("txtFlex"));
RadComboBox ab= (RadComboBox)(dataItem["Company"].FindControl("cboCompany"));
RadComboBox cd= (RadComboBox)(dataItem["FlexAcctCode"].FindControl("cboFlexAcctCode"));
if (!String.IsNullOrEmpty(textBox1.Text))
{
ab.Items.Insert(1, new RadComboBoxItem(textBox1.Text));
ab.SelectedIndex = 0;
textBox1.Text = String.Empty;
}
if (!String.IsNullOrEmpty(textBox2.Text))
{
cd.Items.Insert(1, new RadComboBoxItem(textBox2.Text));
cd.SelectedIndex = 0;
textBox2.Text = String.Empty;
}
}
}
ASP://
<telerik:RadGrid ID="grdFlex" runat="server" AutoGenerateColumns="False"
ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True"
EnableDynamicPageSize="False"
AllowMultiRowSelection="true" EnableToolbar="False" OnNeedDataSource="grdFlex_NeedDataSource"
Width="80%">
<MasterTableView CommandItemDisplay="TopAndBottom" EditMode="InPlace" >
<CommandItemTemplate>
<div style="padding: 5px 5px;">
<telerik:RadButton runat="server" Text="Add new" ID="btnAdd_grdFlex" CommandName="InitInsert"
Visible='<%# !grdFlex.MasterTableView.IsItemInserted %>'>
<Icon PrimaryIconUrl="~/Image/Button/add.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
</telerik:RadButton>
<telerik:RadButton runat="server" AutoPostBack="false" Text="Delete" ID="btnDelete_grdFlex"
OnClientClicked="grdFlex_onDeleteClick" CausesValidation="false" Visible='<%# !grdFlex.MasterTableView.IsItemInserted %>'>
<Icon PrimaryIconUrl="~/Image/Button/remove.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
</telerik:RadButton>
<telerik:RadButton runat="server" Text="Add New record" ID="btnAddRecord_grdFlex" CommandName="PerformInsert" OnCommand="btnAddRecord_grdFlex_performInsert"
Visible='<%# grdFlex.MasterTableView.IsItemInserted %>'>
<Icon PrimaryIconUrl="~/Image/Button/yes.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
</telerik:RadButton>
<telerik:RadButton runat="server" Text="Cancel editing" ID="btnCancel_grdCancel" CommandName="CancelAll"
Visible='<%# grdFlex.EditIndexes.Count > 0 || grdFlex.MasterTableView.IsItemInserted %>'>
<Icon PrimaryIconUrl="~/Image/Button/cancel.gif" PrimaryIconLeft="8" PrimaryIconTop="4" />
</telerik:RadButton>
</div>
</CommandItemTemplate>
...........
<telerik:GridTemplateColumn UniqueName="Company" HeaderText="Company">
<InsertItemTemplate>
<telerik:RadTextBox ID="txtSubcomName" runat="server" ></telerik:RadTextBox>
</InsertItemTemplate>
<ItemTemplate>
<telerik:RadComboBox ID="cboCompany" runat="server" Filter="Contains" AppendDataBoundItems="true" AllowCustomText="True"
Width="100%" SelectedValue='<%# Bind("Company") %>'>
<Items>
<telerik:RadComboBoxItem Text="Yau Lee Construction Co. Ltd" Value="YLC" />
<telerik:RadComboBoxItem Text="Yau Lee Holdings" Value="YLH" />
</Items>
</telerik:RadComboBox>
</ItemTemplate>
<ItemStyle Width="200px" />
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="FlexAcctCode" HeaderText="Flex A/C Code">
<InsertItemTemplate>