如何访问存储在EditItemTemplate中的控件?

时间:2018-06-20 06:22:32

标签: asp.net telerik radgrid

我想访问 batcheditCommand 事件中的控件(存储在edititemtemplate中)。

在我的页面中,我使用的网格负责批量插入和批量更新。让我先向您展示它的设计。

enter image description here

现在让我发布其标记

<telerik:RadGrid ID="rgv_UoMDetails" runat="server" OnNeedDataSource="rgv_UoMDetails_NeedDataSource" Width="100%"
                        Height="220px" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" SelectedItemStyle-BackColor="#003366"
                        OnPreRender="rgv_UoMDetails_PreRender" OnBatchEditCommand="rgv_UoMDetails_BatchEditCommand">
                        <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
                        <MasterTableView CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true" EditMode="Batch"
                            AutoGenerateColumns="False" DataKeyNames="UoMGID" TableLayout="Fixed">
                            <BatchEditingSettings EditType="Row" />
                            <Columns>
                                <telerik:GridNumericColumn DataField="AltQty" DecimalDigits="5" HeaderText="Alt. Qty" HeaderStyle-Width="100px"
                                    UniqueName="AltQty" ItemStyle-HorizontalAlign="Right">
                                </telerik:GridNumericColumn>
                                <telerik:GridTemplateColumn DataField="UoMID" HeaderText="Alt. UoM" HeaderStyle-Width="120px"
                                    UniqueName="AltUoMID">
                                    <ItemTemplate>
                                        <%#Eval("AltUoMCode") %>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <telerik:RadComboBox ID="cmbx_AltUoM" runat="server" Width="100%" Filter="Contains" MarkFirstMatch="true" AutoPostBack="False"
                                            OnClientDropDownOpening="onUoMComboItemRequesting">
                                        </telerik:RadComboBox>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <span>=</span>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridNumericColumn DataField="BaseQty" DecimalDigits="5" HeaderStyle-Width="100px" HeaderText="Base Qty"
                                    UniqueName="BaseQty" ItemStyle-HorizontalAlign="Right">
                                </telerik:GridNumericColumn>
                                <telerik:GridBoundColumn DataField="BaseUoMCode" HeaderStyle-Width="100px" FilterControlAltText="Filter BaseUoMCode column"
                                    HeaderText="Base UoM" UniqueName="BaseUoMCode" ReadOnly="true" DefaultInsertValue="Kg">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <CommandItemSettings AddNewRecordText="" CancelChangesText="" SaveChangesText="" RefreshText="" />
                        </MasterTableView>
                        <ClientSettings AllowKeyboardNavigation="true">
                            <ClientEvents OnBatchEditOpening="BatchEditOpening" OnBatchEditCellValueChanging="BatchEditCellValueChanging"></ClientEvents>
                            <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="220px" SaveScrollPosition="true" />
                            <Resizing AllowColumnResize="true"></Resizing>
                        </ClientSettings>
                    </telerik:RadGrid>

现在让我们说我要对2个或更多项目执行插入操作。

enter image description here

现在,我们单击“保存”(软盘)按钮以触发服务器端事件。

protected void rgv_UoMDetails_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
        {
            foreach (GridBatchEditingCommand command in e.Commands)
            {
                DataTable dtUoMGroupDetailsData2 = ViewState["UoMGroupDetailsData2"] as DataTable;
                string altUom = (rgv_UoMDetails.FindControl(rgv_UoMDetails.MasterTableView.ClientID + "_AltUoMID")
                                    .FindControl("cmbx_AltUoM") as RadComboBox).SelectedValue;
                if (command.Type == GridBatchEditingCommandType.Update)
                {
                    Hashtable newValues = command.NewValues;
                    if (newValues["AltQty"] != null && newValues["BaseQty"] != null && altUom != "" && altUom != "0")
                    {
                        DataRow dr = dtUoMGroupDetailsData2.NewRow();
                        dr["UoMGDID"] = "HC01";
                        dr["UoMGID"] = "HC01";
                        dr["BaseUoMID"] = cmbx_InventoryUoM.SelectedValue;
                        dr["AltUoMID"] = altUom;
                        dr["BaseQty"] = Convert.ToDecimal(newValues["BaseQty"]);
                        dr["AltQty"] = Convert.ToDecimal(newValues["AltQty"]);
                        dr["BaseUoMCode"] = cmbx_InventoryUoM.Text;
                        dr["AltUoMCode"] =
                            (rgv_UoMDetails.FindControl(rgv_UoMDetails.MasterTableView.ClientID + "_AltUoMID")
                                .FindControl("cmbx_AltUoM") as RadComboBox).Text;
                        dtUoMGroupDetailsData2.Rows.Add(dr);
                        ViewState["UoMGroupDetailsData2"] = dtUoMGroupDetailsData2;
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", "alert('Please fix problem first !');", true);
                    }
                }
                if (command.Type == GridBatchEditingCommandType.Insert)
                {
                    Hashtable newValues = command.NewValues;
                    if (newValues["AltQty"] != null && newValues["BaseQty"] != null && altUom != "" && altUom != "0")
                    {
                        DataRow dr = dtUoMGroupDetailsData2.NewRow();
                        dr["UoMGDID"] = "HC01";
                        dr["UoMGID"] = "HC01";
                        dr["BaseUoMID"] = cmbx_InventoryUoM.SelectedValue;
                        dr["AltUoMID"] = altUom;
                        dr["BaseQty"] = Convert.ToDecimal(newValues["BaseQty"]);
                        dr["AltQty"] = Convert.ToDecimal(newValues["AltQty"]);
                        dr["BaseUoMCode"] = cmbx_InventoryUoM.Text;
                        dr["AltUoMCode"] =
                           (rgv_UoMDetails.FindControl(rgv_UoMDetails.MasterTableView.ClientID + "_AltUoMID")
                                .FindControl("cmbx_AltUoM") as RadComboBox).Text;
                        dtUoMGroupDetailsData2.Rows.Add(dr);
                        ViewState["UoMGroupDetailsData2"] = dtUoMGroupDetailsData2;
                    }

                }
            }
        }

在这里,我遇到了问题,在 >插入

注意:

每次执行插入操作时,我都会得到“ Pack”。

0 个答案:

没有答案