or
.aspx<telerik:RadGrid ID="rgBeneficiary" runat="server" GridLines="Vertical" AllowPaging="true" AllowAutomaticUpdates="false" AllowAutomaticInserts="false" AutoGenerateColumns="False" EnableLinqExpressions="false" AllowSorting="true" AllowAutomaticDeletes="false" Skin="MBen" EnableEmbeddedSkins="false" DataSourceID="_dataSrcBeneficiaries" AllowCustomPaging="false" AllowFilteringByColumn="true" Width="100%" OnPreRender="rgBeneficiary_PreRender" OnItemCommand="rgBeneficiary_ItemCommand" OnItemCreated="rgBeneficiary_ItemCreated" PageSize="15" ImagesPath="../../App_Themes/MBen/Grid"> <MasterTableView TableLayout="Fixed" HierarchyDefaultExpanded="false" HierarchyLoadMode="ServerBind" CommandItemDisplay="Top" ExpandCollapseColumn-CollapseImageUrl="../../App_Themes/MBen/Grid/Collapse.gif" HorizontalAlign="Right" ExpandCollapseColumn-Display="false" RowIndicatorColumn-Display="false" ExpandCollapseColumn-ExpandImageUrl="../../App_Themes/MBen/Grid/Expand.gif"> <CommandItemSettings ShowRefreshButton="false" ShowExportToExcelButton="true" ExportToExcelText="" ExportToCsvText="" ExportToPdfText="" ExportToWordText="" ShowExportToPdfButton="true" ShowExportToWordButton="true" ShowExportToCsvButton="true" ShowAddNewRecordButton="false" /> <Columns> <telerik:GridTemplateColumn UniqueName="TemplateColumn" AllowFiltering="false" HeaderStyle-Width="3%"> <ItemTemplate> <asp:ImageButton ID="btnCollapse" runat="server" CommandName="ExpandCollapse" ImageUrl="~/App_Themes/MBen/Grid/Collapse.gif" ToolTip="Collapse" Visible="False " /> <asp:ImageButton ID="btnExpand" runat="server" CommandName="ExpandCollapse" ImageUrl="~/App_Themes/MBen/Grid/Expand.gif" ToolTip="Expand" /> </ItemTemplate> <HeaderTemplate> <asp:ImageButton ID="ExpandAll" runat="server" CommandName="ExpandAll" ImageUrl="~/App_Themes/MBen/Grid/Expand.gif" ToolTip="ExpandAll" /> <asp:ImageButton ID="CollapseAll" runat="server" CommandName="CollapseAll" Visible="False" ImageUrl="~//App_Themes/MBen/Grid/Collapse.gif" ToolTip="CollapseAll" /> </HeaderTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn DataField="FullName" UniqueName="FullName" HeaderText="Participant Name" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="125px" FilterControlToolTip="Input name or part of name to search"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="EmployeeCode" UniqueName="EmployeeCode" HeaderText="Participant Code" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="75px" FilterControlToolTip="Input a code to search" /> </Columns> <DetailTables> <telerik:GridTableView DataKeyNames="BeneficiaryID" DataSourceID="_dataSrcParticipantBeneficiaries" Width="100%" runat="server" AllowFilteringByColumn="false" ShowFooter="true" HorizontalAlign="Right"> <ParentTableRelation> <telerik:GridRelationFields DetailKeyField="ParticipantID" MasterKeyField="ParticipantID" /> </ParentTableRelation> <Columns> <telerik:GridBoundColumn DataField="BeneficiaryID" UniqueName="BeneficiaryID" Visible="false"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Beneficiary" UniqueName="Beneficiary" HeaderText="Beneficiary Name" AllowFiltering="false"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BeneficiaryType" UniqueName="BeneficiaryType" HeaderText="Beneficiary Type" HeaderStyle-Width="15%"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BeneficiaryRelationship" UniqueName="BeneficiaryRelationship" HeaderText="Relationship" AllowFiltering="false" HeaderStyle-Width="15%"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BeneficiaryPercent" UniqueName="BeneficiaryPercent" HeaderText="Beneficiary Percent" AllowFiltering="false" HeaderStyle-Width="18%"> </telerik:GridBoundColumn> </Columns> </telerik:GridTableView> </DetailTables> </MasterTableView> </telerik:RadGrid>protected void rgBeneficiary_PreRender(object source, EventArgs e) { if (rgBeneficiary.MasterTableView.Items.Count == 0) { rgBeneficiary.ShowFooter = false; } RadAjaxManager.GetCurrent(Page).ClientEvents.OnRequestStart = "RequestStart"; } protected void rgBeneficiary_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName.Contains("Export")) { if (e.CommandName == "ExportToCsv") rgBeneficiary.ExportSettings.ExportOnlyData = false; rgBeneficiary.MasterTableView.HierarchyDefaultExpanded = true; } #region Expand/Collapse All if (e.CommandName == RadGrid.ExpandCollapseCommandName) { (e.Item.FindControl("btnExpand") as ImageButton).Visible = !(e.Item.FindControl("btnExpand") as ImageButton).Visible; (e.Item.FindControl("btnCollapse") as ImageButton).Visible = !(e.Item.FindControl("btnCollapse") as ImageButton).Visible; } if (e.CommandName == "ExpandAll") { //Looping through each DataItem and making the "btnExpand" image button in the item visibility to false and "btnCollapse" visibility to true foreach (GridDataItem GridDataItem in rgBeneficiary.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem })) { ImageButton btnExpand = (ImageButton)GridDataItem.FindControl("btnExpand"); btnExpand.Visible = false; ImageButton btnCollapse = (ImageButton)GridDataItem.FindControl("btnCollapse"); btnCollapse.Visible = true; } //Exapanding the DataItem foreach (GridDataItem item in rgBeneficiary.Items) { item.Expanded = true; } //Hiding the CollapseAll image in the header to true and ExpandAll image in the header to false GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem; ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll"); imgCollapseAll.Visible = true; ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll"); imgExpandAll.Visible = false; } if (e.CommandName == "CollapseAll") { //Looping through each DataItem and making the "btnExpand" image button in the item visibility to true and "btnCollapse" visibility to false foreach (GridDataItem GridDataItem in rgBeneficiary.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem })) { ImageButton btnExpand = (ImageButton)GridDataItem.FindControl("btnExpand"); btnExpand.Visible = true; ImageButton btnCollapse = (ImageButton)GridDataItem.FindControl("btnCollapse"); btnCollapse.Visible = false; } //Collapsing the DataItem foreach (GridDataItem item in rgBeneficiary.Items) { item.Expanded = false; } //Hiding the CollapseAll image in the header to false and ExpandAll image in the header to true GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem; ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll"); imgCollapseAll.Visible = false; ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll"); imgExpandAll.Visible = true; } #endregion } protected void rgBeneficiary_ItemCreated(object source, GridItemEventArgs e) { //removes unwanted line from commanditemdisplay if (e.Item is GridCommandItem) { ((Table)e.Item.Cells[0].Controls[0]).Rows[0].Cells[1].Controls.RemoveAt(1); } }
OnUpdateCommand="RadGrid2_UpdateCommandfor the first version and
OnItemCommand="RadGrid1_ItemCommand"for the second version.
First I put radgrid item in editmode with first button:
RadGrid2.EditIndexes.Add(0);RadGrid2.Rebind();if (commandButton.CommandName.ToLower() == "update") { foreach (GridEditFormItem item in RadGrid2.MasterTableView.GetItems(GridItemType.EditFormItem)) { RadGrid2.MasterTableView.PerformUpdate(item, true); // first version item.FireCommandEvent("Update", string.Empty); //second version }
<EditFormSettings EditFormType="Template" > <EditColumn UniqueName="EditColumn"></EditColumn> <FormTemplate> <div> <tr> <td> Inicijali </td> <td> <telerik:RadTextBox ID="Inicijali" runat="server" Font-Names="Verdana" Font-Size="Small" Text='<%# Bind("Inicijali") %>'> </telerik:RadTextBox> </td> </tr> <tr> <td> Kratica imena </td> <td> <telerik:RadTextBox ID="KraticaImena" runat="server" Font-Names="Verdana" Font-Size="Small" Text='<%# Bind("KraticaImena") %>'> </telerik:RadTextBox> </td> </tr>.....</table>RadGrid definition:
<telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="DetailsViewSQLDataSource" AutoGenerateColumns="false" OnUpdateCommand="RadGrid2_UpdateCommand" OnItemCommand="RadGrid1_ItemCommand" AllowAutomaticUpdates="true"> <MasterTableView DataSourceID="DetailsViewSQLDataSource" AutoGenerateColumns="true" DataKeyNames="IdOsobe" ShowHeader="false" EditMode="EditForms" AllowAutomaticInserts="true">protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == RadGrid.UpdateCommandName) { if (e.Item is GridEditFormItem) { GridEditFormItem item = (GridEditFormItem)e.Item; int id = Convert.ToInt32(item.GetDataKeyValue("IdOsobe")); if (id != 0) { RadTextBox txtInicijali = (RadTextBox)item.FindControl("Inicijali"); RadGrid1.Rebind(); } } } }