先生/女士,
我将通过单击添加来开发插入命令,以将 RadTextbox 显示为 InsertItem 模板,并在将所有数据输入到 RadGrid 内后单击添加新记录
但是进入测试时发现Getting the Items 无法完成,总是显示null
以下是我的代码,请回答
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>