Hi All,
I am using RadGrid in my application. I am fetching around 10 to 15 columns from the database and filling the RadGrid. As per the requirement, i have to display only specific columns in the Grid.
For this, I am hiding the columns from the user using javascript, which would not be displayed to the user.
I should also have to hide these columns in header context menu of RadGrid.
Can anyone please help to solve this issue?
Thanks,
KKB.
Modal
="true"
However the entire window including the pop up window greys out. Any one have a solution for this.
Thanks
function OnClientDockPositionChanged(sender, args) {
alert(sender.get_dockZoneID());
alert(sender.get_uniqueID());
alert(sender.get_collapsed());
alert(sender.get_closed());
}
Do you have an example when the state of the docks is saved and loaded using web service call through AJAX's
PageMethods?
| C# |
| [WebMethod] |
| public static RadTreeNodeData[] LoadNodes(RadTreeNodeData node) // called each time a node is expanded |
| { |
| AttributeService.Attribute atts = new AttributeService.Attribute(); |
| List<RadTreeNodeData> result = new List<RadTreeNodeData>(); |
| DataSet ds = new DataSet(), ads = new DataSet(); |
| DataTable data = new DataTable(), attributeData = new DataTable(); |
| int WebP_Id = Int32.Parse(HttpContext.Current.Session["WebPID"].ToString()); |
| ArrayList RadNodeChanged = new ArrayList(); |
| ds = atts.GetChildrenByWebpId(WebP_Id, Convert.ToInt32(node.Value)); // gets the children for a specific item |
| data = ds.Tables[0]; |
| foreach (DataRow row in data.Rows) |
| { |
| RadTreeNodeData childNode = new RadTreeNodeData(); |
| childNode.Text = row["AttributeName"].ToString(); // adds the name and the text to "childNode" |
| childNode.Value = row["Attribute_Id"].ToString(); |
| if (atts.GetAllChildren(Convert.ToInt32(childNode.Value)).Tables[0].Rows.Count > 0) |
| { |
| childNode.ExpandMode = TreeNodeExpandMode.WebService; |
| } |
| //can code go here to make the color of the node red when the parent is expanded? |
| //attributeData = atts.GetAttributes(WebP_Id).Tables[0]; |
| //foreach (DataRow dr in attributeData.Rows) |
| //{ |
| // if (String.Compare(dr["AttributeId"].ToString(), childNode.Value) == 0) |
| // { |
| // childNode.Attributes["ForeColor"] = System.Drawing.Color.Red; |
| // } |
| //} //doesn't work |
| result.Add(childNode); |
| } |
| return result.ToArray(); |
| } |
| private static void LoadRootAttributeNodes(RadTreeView treeView, TreeNodeExpandMode expandMode) |
| { |
| AttributeService.Attribute attser = new AttributeService.Attribute(); // function is called to set the origin nodes |
| int WebP_Id = Int32.Parse(HttpContext.Current.Session["WebPID"].ToString()); |
| DataSet ds = new DataSet(); |
| ArrayList Cat = new ArrayList(); |
| DataTable dt = new DataTable(); |
| ds = attser.GetChildrenByWebpId(WebP_Id, 0); // zero being for the high level parent nodes |
| dt = ds.Tables[0]; |
| foreach (DataRow row in dt.Rows) |
| { |
| RadTreeNode node = new RadTreeNode(); |
| node.Text = row["AttributeName"].ToString(); |
| node.Value = row["Attribute_Id"].ToString(); |
| node.ExpandMode = expandMode; |
| treeView.Nodes.Add(node); |
| } |
| } |
| protected void AttributesTree_HandleDrop(object sender, RadTreeNodeDragDropEventArgs e) |
| { //drag and drop function, when an item is released from the tree, this function will be called |
| RadTreeNode sourceNode = e.SourceDragNode, destNode = e.DestDragNode; |
| RadTreeViewDropPosition dropPosition = e.DropPosition; |
| AttributeService.Attribute atts = new AttributeService.Attribute(); |
| ArrayList deletedCat = new ArrayList(); |
| DataSet ds = new DataSet(); |
| DataTable dt = (DataTable)Session["AttributesTable"]; |
| bool existsInList = false; |
| Session["TreeView"] = AttributeTree; |
| foreach (GridDataItem dataItem in CurrentAttributesList.Items) |
| { |
| if (dataItem.ForeColor == System.Drawing.Color.Red) |
| { |
| deletedCat.Add(dataItem["AttributeId"].Text); |
| } |
| } |
| foreach (RadTreeNode node in e.DraggedNodes) |
| { |
| existsInList = false; |
| foreach ( GridDataItem item in CurrentAttributesList.Items ) |
| { |
| if (item["AttributeId"].Text == node.Value) |
| { |
| existsInList = true; |
| } |
| } |
| if (existsInList) |
| { |
| Master.AttributePublishErrorMessage = "Please use an attribute that is not in the list"; // duplicate item |
| } |
| else |
| { |
| ds = atts.GetAttributeByAttributeID(Convert.ToInt32(node.Value)); |
| if (ds.Tables.Count > 0) |
| { |
| foreach (DataRow dr in ds.Tables[0].Rows) |
| { |
| if (String.Compare(dr["Parent_ID"].ToString(), "0") == 0) |
| { |
| Master.AttributePublishErrorMessage = "Please use the lowest possible, non-parent attribute available."; |
| } |
| else |
| { |
| dt.Rows.Add(dr["Attribute_ID"], dr["AttributeName"], dr["AttributePath"]); |
| foreach (RadTreeNode currentnode in AttributeTree.SelectedNodes) |
| { |
| currentnode.ForeColor = System.Drawing.Color.Red; |
| RadTreeNodeChanged.Add(currentnode.Value); |
| } |
| } |
| } |
| } |
| } |
| } |
| Session["AttributesTable"] = dt; |
| CurrentAttributesList.DataSource = dt; |
| CurrentAttributesList.DataBind(); |
| for (int i = 0; i < CurrentAttributesList.Items.Count; i++) |
| { |
| for (int j = 0; j < deletedCat.Count; j++) |
| { |
| if (CurrentAttributesList.Items[i]["AttributeId"].Text == deletedCat[j].ToString()) |
| { |
| CurrentAttributesList.Items[i].Font.Strikeout = true; |
| CurrentAttributesList.Items[i].ForeColor = System.Drawing.Color.Red; |
| } |
| } |
| } |
| } |
| public void CurrentAttributes(int webp_id) |
| { |
| AttributeService.Attribute atts = new AttributeService.Attribute(); |
| DataSet attributes = atts.GetAttributes(webp_id); |
| DataTable attributeData = attributes.Tables[0]; |
| CurrentAttributesList.DataSource = attributeData; |
| CurrentAttributesList.DataBind(); |
| Session["AttributesTable"] = attributeData; |
| } |
| protected void CurrentAttributesList_Command(Object source, CommandEventArgs e) |
| { // the rad grid function when a command for save, delete, or refresh |
| int getWebP_Id = GetValidWebpId(SearchBox.Text), listIndex; |
| WebServiceProxy wsp = new WebServiceProxy(); |
| switch (e.CommandName) |
| { |
| case "SaveChanges": //when the command is save, the attribute will be saved to the database |
| AttributeService.Attribute atts = new AttributeService.Attribute(); |
| CategoryStatus attributeStatus, status; |
| currentAttributes = new ArrayList(); |
| DataSet CurrentAttributeList = atts.GetAttributes(getWebP_Id); |
| // load the current categories into a list, stores the status of each cat id |
| foreach (DataRow dataRowAttribute in CurrentAttributeList.Tables[0].Rows) |
| { |
| attributeStatus.CatId = Convert.ToString(dataRowAttribute["AttributeId"]); |
| attributeStatus.Status = 0; |
| attributeStatus.Primary = false; |
| currentAttributes.Add(attributeStatus); |
| } |
| // cycles through the rad grid to detect changes |
| foreach (GridDataItem dataItem in CurrentAttributesList.Items) |
| { |
| string catid = dataItem["AttributeId"].Text; |
| listIndex = FindInList(catid, currentAttributes); |
| if (dataItem.ForeColor == System.Drawing.Color.Red) |
| { |
| updateListStatus(currentAttributes, ListStatus.Remove, listIndex); |
| } |
| if (listIndex < 0) //not in the list, needs to be added |
| { |
| status.CatId = catid; |
| status.Status = ListStatus.AddPrimary; |
| status.Primary = false; |
| currentAttributes.Add(status); |
| } |
| else |
| { |
| status = (CategoryStatus)currentAttributes[listIndex]; |
| } |
| } |
| // stores the status of each cat id (add, remove, or no change) |
| foreach (CategoryStatus cs in currentAttributes) |
| { |
| switch (cs.Status) |
| { |
| case ListStatus.NoChange: |
| break; |
| case ListStatus.AddPrimary: |
| wsp.AddProductAttribute(getWebP_Id, Convert.ToInt32(cs.CatId), Request.ServerVariables["auth_user"], 0); |
| break; |
| case ListStatus.Remove: |
| wsp.DeleteProductAttributes(getWebP_Id, Convert.ToInt32(cs.CatId)); |
| break; |
| } |
| } |
| CurrentAttributes(getWebP_Id); |
| case "DeleteSelected": |
| // using a for loop to loop through each item, then set the selected ones to be red and struck through |
| // need to call a rebind instead of binding to a table to keep font attributes |
| for (int i = 0; i < CurrentAttributesList.Items.Count; i++) |
| { |
| if (CurrentAttributesList.Items[i].Selected) |
| { |
| CurrentAttributesList.Items[i].Font.Strikeout = true; |
| CurrentAttributesList.Items[i].ForeColor = System.Drawing.Color.Red; |
| } |
| } |
| CurrentAttributesList.Rebind(); |
| break; |
| case "RebindGrid": // refresh grid back to original state, before any changes were made after hitting the save button |
| getWebP_Id = GetValidWebpId(SearchBox.Text); |
| CurrentAttributes(getWebP_Id); |
| foreach (string id in RadTreeNodeChanged) |
| { |
| ControlItem node = AttributeTree.FindChildByValue <ControlItem> (id); |
| node.ForeColor = System.Drawing.Color.Black; //doesn't work |
| } |
| break; |
| default: |
| break; |
| } |
| } |
| ASPX: |
| <asp:Content ID="CurrentAttributes" runat="server" ContentPlaceHolderID="AttributesRightContent"> |
| <asp:UpdatePanel ID="UpdatePanel1" runat="server"> |
| <contenttemplate> |
| <telerik:RadGrid ID="CurrentAttributesList" runat="server" Skin="Vista" AllowMultiRowSelection="true" Height="448px" AllowPaging="true" PageSize="20" AllowAutomaticDeletes="true"> |
| <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="AttributeID"> |
| <CommandItemTemplate> |
| <div style="padding: 5px 5px;"> |
| <asp:LinkButton ID="btnSaveSelected" runat="server" CommandName="SaveChanges" OnCommand="CurrentAttributesList_Command"><img style="border:0px;vertical-align:middle;" alt="" src="Images/save.png" /> Accept Changes</asp:LinkButton> |
| <asp:LinkButton ID="btnDeleteSelected" OnClientClick="javascript:return confirm('Delete selected attributes?')" runat="server" CommandName="DeleteSelected" OnCommand="CurrentAttributesList_Command"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Cancel.gif" /> Delete selected customers</asp:LinkButton>   |
| <asp:LinkButton ID="btnRefreshGrid" runat="server" CommandName="RebindGrid" OnCommand="CurrentAttributesList_Command"><img style="border:0px;vertical-align:middle;" alt="" src="Images/refresh.png" /> Refresh attributes list to original</asp:LinkButton> |
| </div> |
| </CommandItemTemplate> |
| </MasterTableView> |
| <ClientSettings> |
| <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| </contenttemplate> |
| </asp:UpdatePanel> |
| </asp:Content> |
| <asp:Content ID="AttributesTree" runat="server" ContentPlaceHolderID="AttributesLeftContent"> |
| <asp:UpdatePanel id="AttributeUpdatePanel" runat="server" UpdateMode="Conditional"> |
| <contenttemplate> |
| <div class="DivAlignLeft"></div> |
| <div class="DivAlignRight"></div> |
| <telerik:RadTreeView ID="AttributeTree" runat="server" Skin="Vista" EnableDragAndDrop="true" |
| OnNodeDrop="AttributesTree_HandleDrop" OnClientNodeDropping="onNodeDropping" |
| OnClientNodeDragging="onNodeDragging" MultipleSelect="true"> |
| <WebServiceSettings Path="ProductsScreen.aspx" Method="LoadNodes" /> |
| </telerik:RadTreeView> |
| </contenttemplate> |
| </asp:UpdatePanel> |
| </asp:Content> |
<style type="text/css">
.selectedItem {
background-color: #FFD92F !important;
color: #000000 !important;
}
.rmItem { border-right: 1px solid white; }
.rmItem { border-top: 1px solid #7F8ECB; }
</style>
Dim currentItem as Telerik.Web.UI.RadMenuItem
currentItem = radMenu1.FindItemByText(
"Forms")
currentItem.CssClass=
"SelectedItem"
Thanks,
Susan Pelzel