or
|
Requirements |
|
| RadControls version 2009Q2 Trial |
|
| .NET version 3.5 SP1 |
|
| Visual Studio version 2008 SP1 |
|
| programming language C# |
|
| browser support |
all browsers supported by RadControls |
| <telerik:RadGrid ID="radGridDivisions" runat="server" AllowPaging="false" |
| AllowSorting="false" AutoGenerateColumns="False" GridLines="Horizontal" |
| oninsertcommand="radGridDivisions_InsertCommand" |
| onupdatecommand="radGridDivisions_UpdateCommand" |
| ondeletecommand="radGridDivisions_DeleteCommand" |
| onitemdatabound="radGridDivisions_ItemDataBound" |
| onneeddatasource="radGridDivisions_NeedDataSource" |
| OnColumnCreated="radGridDivisions_ColumnCreated" |
| OnItemCreated="radGridDivisions_ItemCreated" |
| Skin="Default" ShowHeader="true"> |
| <ClientSettings AllowExpandCollapse="true" /> |
| <mastertableview commanditemdisplay="Top" datakeynames="ID, ParentID" |
| editmode="EditForms" name="Master" nomasterrecordstext="Det finns inga divisioner" |
| HierarchyDefaultExpanded="true" HierarchyLoadMode="Client"> |
| <SelfHierarchySettings ParentKeyName="ParentID" KeyName="ID" /> |
| <commanditemsettings addnewrecordtext="Lägg till" refreshtext="Uppdatera" /> |
| <Columns> |
| <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="Id" Visible="false" /> |
| <telerik:GridBoundColumn UniqueName="ParentID" DataField="ParentID" HeaderText="Parent Id" Visible="false" /> |
| <telerik:GridBoundColumn UniqueName="Name" Headertext="Division" DataField="Name" /> |
| <telerik:GridCheckBoxColumn UniqueName="IsEnabled" HeaderText="Aktiverad" DataField="IsEnabled" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" /> |
| <telerik:GridDateTimeColumn DataField="CreateDate" DataFormatString="{0:g}" |
| HeaderStyle-HorizontalAlign="Right" HeaderText="Skapad" |
| ItemStyle-HorizontalAlign="Right" ReadOnly="true" UniqueName="CreateDate" SortExpression="e.CreateDate"> |
| <HeaderStyle HorizontalAlign="Right" /> |
| <ItemStyle HorizontalAlign="Right" /> |
| </telerik:GridDateTimeColumn> |
| <telerik:GridEditCommandColumn CancelText="Avbryt" EditText="Ändra" InsertText="Spara" UpdateText="Spara" ButtonType="ImageButton" UniqueName="EditCommandColumn"> |
| <HeaderStyle HorizontalAlign="Right" Width="20" /> |
| <ItemStyle HorizontalAlign="Right" Width="20" /> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" |
| ConfirmText="Är du säker på att du vill radera denna division?" |
| ConfirmTitle="Delete" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="20px" |
| Text="Radera" UniqueName="DeleteColumn"> |
| <ItemStyle HorizontalAlign="Right" Width="20px" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| </mastertableview> |
| </telerik:RadGrid> |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| radGridDivisions.MasterTableView.FilterExpression = "ParentID.Equals(Guid.Empty)"; |
| } |
| public void Page_PreRenderComplete(object sender, EventArgs e) |
| { |
| HideExpandColumnRecursive(radGridDivisions.MasterTableView); |
| } |
| public void HideExpandColumnRecursive(GridTableView tableView) |
| { |
| GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView); |
| foreach (GridNestedViewItem nestedViewItem in nestedViewItems) |
| { |
| foreach (GridTableView nestedView in nestedViewItem.NestedTableViews) |
| { |
| nestedView.Style["border"] = "0"; |
| Button MyExpandCollapseButton = (Button)nestedView.ParentItem.FindControl("MyExpandCollapseButton"); |
| if (nestedView.Items.Count == 0) |
| { |
| if (MyExpandCollapseButton != null) |
| { |
| MyExpandCollapseButton.Style["visibility"] = "hidden"; |
| } |
| nestedViewItem.Visible = false; |
| } |
| else |
| { |
| if (MyExpandCollapseButton != null) |
| { |
| MyExpandCollapseButton.Style.Remove("visibility"); |
| } |
| } |
| if (nestedView.HasDetailTables) |
| { |
| HideExpandColumnRecursive(nestedView); |
| } |
| } |
| } |
| } |
| protected void radGridDivisions_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| //int recordCount; |
| string search = textBoxSearch.Text.Trim(); |
| //foreach (Division d in DivisionService.GetDivisions()) |
| // Response.Write(d.Name); |
| radGridDivisions.DataSource = DivisionService.GetDivisions();//.GetDivisions(null, search, "", 0, 0, out recordCount); |
| //radGridDivisions.VirtualItemCount = recordCount; |
| } |
| protected void radGridDivisions_ColumnCreated(object sender, GridColumnCreatedEventArgs e) |
| { |
| if (e.Column is GridExpandColumn) |
| { |
| e.Column.Visible = false; |
| } |
| else if (e.Column is GridBoundColumn) |
| { |
| //e.Column.HeaderStyle.Width = Unit.Pixel(100); |
| } |
| } |
| protected void radGridDivisions_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| //CreateExpandCollapseButton(e.Item, "Name"); |
| //Response.Write(e.Item.GetType().ToString() + "<br />"); |
| if ((e.Item is GridHeaderItem || e.Item is GridCommandItem) && e.Item.OwnerTableView != radGridDivisions.MasterTableView) |
| { |
| e.Item.Style["display"] = "none"; |
| } |
| /* |
| if (e.Item is GridHeaderItem && e.Item.OwnerTableView != radGridDivisions.MasterTableView) |
| { |
| e.Item.Style["display"] = "none"; |
| } |
| */ |
| if (e.Item is GridNestedViewItem) |
| { |
| e.Item.Cells[0].Visible = false; |
| } |
| } |
| public void CreateExpandCollapseButton(GridItem item, string columnUniqueName) |
| { |
| if (item is GridDataItem) |
| { |
| if (item.FindControl("MyExpandCollapseButton") == null) |
| { |
| Division division = (Division)item.DataItem; |
| Button button = new Button(); |
| button.Click += new EventHandler(button_Click); |
| button.CommandName = "ExpandCollapse"; |
| button.CssClass = (item.Expanded) ? "rgCollapse" : "rgExpand"; |
| button.ID = "MyExpandCollapseButton"; |
| if (item.OwnerTableView.HierarchyLoadMode == GridChildLoadMode.Client) |
| { |
| string script = String.Format(@"$find(""{0}"")._toggleExpand(this, event); return false;", item.Parent.Parent.ClientID); |
| button.OnClientClick = script; |
| } |
| int level = item.ItemIndexHierarchical.Split(':').Length; |
| if (level > 1) |
| { |
| button.Style["margin-left"] = level + 10 + "px"; |
| } |
| TableCell cell = ((GridDataItem)item)[columnUniqueName]; |
| cell.Controls.Add(button); |
| cell.Controls.Add(new LiteralControl(" ")); |
| cell.Controls.Add(new LiteralControl(division.Name)); |
| //cell.Controls.Add(new LiteralControl(((GridDataItem)item).GetDataKeyValue("ID").ToString())); |
| } |
| } |
| } |
| void button_Click(object sender, EventArgs e) |
| { |
| ((Button)sender).CssClass = (((Button)sender).CssClass == "rgExpand") ? "rgCollapse" : "rgExpand"; |
| } |
| protected void radGridDivisions_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| CreateExpandCollapseButton(e.Item, "Name"); |
| GridDataItem gridItem; |
| GridEditFormItem gridEditItem; |
| Division division; |
| switch (e.Item.OwnerTableView.Name) |
| { |
| case "Master": |
| if (e.Item is GridDataItem) |
| { |
| gridItem = (GridDataItem)e.Item; |
| division = (Division)gridItem.DataItem; |
| } |
| break; |
| } |
| } |
I previously had a RadGrd nested like so:
RadSplitter => RadSplitter => RadGrid (i.e. RadGrid nested 2 Splitters deep)
Then on the AjaxManager's ClientEvents-OnResponseEnd, my Javascript looked like so:
| function setDimensions(sender, args) { |
| var splitter = $find(PageControls.RadSplitter1.id); |
| if (splitter != null) |
| splitter.resize(contentPaneWidth - 60, contentPaneHeight - 80); |
| } |

hi ,,
I am using rad grid at webpart , using NestedItem at Grid but after Add Events Fixup Ajax working fine at all grid but i faced 2 issues please help me to find a soultion on them ...
1- the collapse buttom didn't work ( the grid post back and then the nested item didn't collapsed).
2- I can't expand more than 1 nested item at , if i trying to open nested item and it was one else opened the previous one collapsed and the new one expanded ,
here is rad grid code
| <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" Skin="WebBlue" |
| AllowFilteringByColumn="true" dir="rtl" GridLines="None" AllowPaging="True" AllowSorting="True" |
| PageSize="15"> |
| <PagerStyle Mode="NumericPages" HorizontalAlign="Center" Font-Bold="true" VerticalAlign="Middle"> |
| </PagerStyle> |
| <GroupingSettings CaseSensitive="false" /> |
| <ItemStyle HorizontalAlign="Right" /> |
| <FilterItemStyle HorizontalAlign="Right" /> |
| <CommandItemStyle HorizontalAlign="Left" /> |
| <AlternatingItemStyle HorizontalAlign="Right" /> |
| <HeaderStyle HorizontalAlign="Right" /> |
| <MasterTableView DataKeyNames="STUDENTNO" GridLines="None" DataSourceID="ObjectDataSource1" |
| CommandItemDisplay="Top"> |
| <NoRecordsTemplate> |
| </NoRecordsTemplate> |
| <ExpandCollapseColumn Visible="True"> |
| </ExpandCollapseColumn> |
| <CommandItemTemplate> |
| <asp:LinkButton ID="clearFilter" runat="server" Text="Ù…Ø³Ø ÙƒÙ„ Ø§Ù„Ø¨ØØ«" ToolTip="الغاء Ø§Ù„Ø¨ØØ«" |
| OnClick="ClearFilter_Click" Font-Bold="true" Font-Size="14px"></asp:LinkButton> |
| </CommandItemTemplate> |
| <Columns> |
| ... SOME COLUMNS ... |
| </Columns> |
| <NestedViewTemplate> |
| <table> |
| ... NESTED TEMPATE GOES HERE ... |
| </table> |
| </NestedViewTemplate> |
| </MasterTableView> |
| <ClientSettings> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| #region Events & Fixers |
| protected override void OnInit(EventArgs e) |
| { |
| base.OnInit(e); |
| ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page); |
| if (scriptManager == null) |
| { |
| scriptManager = new ScriptManager(); |
| scriptManager.ID = "ScriptManager1"; |
| this.Page.Form.Controls.AddAt(0, scriptManager); |
| } |
| RadAjaxManager ram = RadAjaxManager.GetCurrent(this.Page); |
| if (ram == null) |
| { |
| ram = new RadAjaxManager(); |
| ram.ID = "RadAjaxManager1"; |
| Page.Form.Controls.Add(ram); |
| Page.Items.Add(ram.GetType(), ram); |
| } |
| EnsureChildControls(); |
| } |
| protected override void OnPreRender(EventArgs e) |
| { |
| base.OnPreRender(e); |
| RadAjaxManager manager = RadAjaxManager.GetCurrent(Page); |
| if (manager != null) |
| { |
| manager.DefaultLoadingPanelID = this.EmployeesListUserControl.AjaxLoadingPanel.ID; |
| manager.AjaxSettings.AddAjaxSetting(this.EmployeesListUserControl.GridRootDep, this.EmployeesListUserControl.GridRootDep); |
| } |
| } |
| private void EnsureUpdatePanelFixups() |
| { |
| if (this.Page.Form != null) |
| { |
| string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"]; |
| if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();") |
| { |
| this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();"; |
| } |
| } |
| ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true); |
| } |
| protected override void Render(HtmlTextWriter writer) |
| { |
| EnsureUpdatePanelFixups(); |
| base.Render(writer); |
| } |
| #endregion |