or
|
||||
| protected void rmEntities_ItemDataBound(object sender, RadMenuEventArgs e) | |
| { | |
| string targetURL = | |
| ( (DataBinder.Eval(e.Item.DataItem, "TargetURL") == null) | |
| || | |
| (string.IsNullOrEmpty(DataBinder.Eval(e.Item.DataItem, "TargetURL").ToString())) | |
| ) | |
| ? "#" | |
| : DataBinder.Eval(e.Item.DataItem, "TargetURL").ToString(); | |
| if (e.Item.Level == 0) | |
| { | |
| // start a link tag with our node class | |
| e.Item.Controls.Add(new LiteralControl("<a href='" + targetURL + "' class='EntityParentNode'>")); | |
| // add title | |
| Panel pnlTitle = new Panel(); | |
| pnlTitle.CssClass = "EntityParentTitle"; | |
| pnlTitle.Controls.Add(new LiteralControl(DataBinder.Eval(e.Item.DataItem, "NodeName").ToString())); | |
| e.Item.Controls.Add(pnlTitle); | |
| } | |
| else if (e.Item.Level > 0) | |
| { | |
| // start a link tag with our node class | |
| e.Item.Controls.Add(new LiteralControl("<a href='" + targetURL + "' class='EntityNode'>")); | |
| // add image | |
| Image img = new Image(); | |
| img.ImageUrl = PortalConfig.CategoryImagePath | |
| + DataBinder.Eval(e.Item.DataItem, "ImageFile").ToString(); | |
| img.Height = new Unit("75px"); | |
| img.Width = new Unit("75px"); | |
| img.CssClass = "EntityImage"; | |
| e.Item.Controls.Add(img); | |
| // add title | |
| Panel pnlTitle = new Panel(); | |
| pnlTitle.CssClass = "EntityTitle"; | |
| pnlTitle.Controls.Add(new LiteralControl(DataBinder.Eval(e.Item.DataItem, "NodeName").ToString())); | |
| e.Item.Controls.Add(pnlTitle); | |
| // add description | |
| Panel pnlDescription = new Panel(); | |
| pnlDescription.CssClass = "EntityDescription"; | |
| pnlDescription.Controls.Add(new LiteralControl(DataBinder.Eval(e.Item.DataItem, "EntityDescription").ToString())); | |
| e.Item.Controls.Add(pnlDescription); | |
| } | |
| // close the link tag | |
| e.Item.Controls.Add(new LiteralControl("</a>")); | |
| // set additional css classes | |
| e.Item.ExpandedCssClass = "NodeHighlight"; | |
| e.Item.FocusedCssClass = "NodeHighlight"; | |
| } |
| .rmItem | |
| { | |
| font-family: Verdana; | |
| background-color: White; | |
| } | |
| .rmItem a, | |
| .rmItem a:visited | |
| { | |
| display: block; | |
| color: #000000; | |
| text-decoration: none; | |
| } | |
| .rmItem a:hover | |
| { | |
| color: #00847C; | |
| text-decoration: none; | |
| } | |
| .NodeHighlight | |
| { | |
| } | |
| .HasChildren | |
| { | |
| background-image:url("images/arrowright.png"); | |
| background-position: right center; | |
| background-repeat: no-repeat; | |
| } | |
| .rmGroup | |
| { | |
| border: 1px solid #666666; | |
| } | |
| .EntityParentNode | |
| { | |
| font-size: 12px; | |
| text-align: left; | |
| vertical-align: middle; | |
| line-height: 20px; | |
| cursor: pointer; | |
| width: 190px; | |
| } | |
| .EntityParentTitle | |
| { | |
| padding-left: 2px; | |
| width: 176px; | |
| overflow: hidden; | |
| white-space: nowrap; | |
| } | |
| .EntityNode | |
| { | |
| padding: 2px; | |
| width: 285px; | |
| cursor: pointer; | |
| white-space: normal !important; | |
| width: 290px; | |
| text-align: left; | |
| } | |
| .EntityImage | |
| { | |
| float: left; | |
| } | |
| .EntityTitle | |
| { | |
| padding-left: 2px; | |
| vertical-align: middle; | |
| font-size: 12px; | |
| font-weight: bold; | |
| overflow: hidden; | |
| height: 18px; | |
| width: 200px; | |
| } | |
| .EntityDescription | |
| { | |
| padding-left: 2px; | |
| vertical-align: middle; | |
| font-size: 11px; | |
| overflow: hidden; | |
| height: 56px; | |
| width: 200px; | |
| white-space: normal !important; | |
| } |
| <%@ Page Language="C#" MasterPageFile="~/Masters/Site.Master" AutoEventWireup="true" |
| CodeBehind="Nouns.aspx.cs" Inherits="MIDI_Internal.Lookups.NSNs.Nouns" Title="MIDI - Manage Nouns" %> |
| <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" |
| Namespace="System.Web.UI" TagPrefix="asp" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> |
| </asp:Content> |
| <asp:Content ID="Content2" ContentPlaceHolderID="cphPageTitle" runat="server"> |
| Manage Nouns |
| </asp:Content> |
| <asp:Content ID="Content3" ContentPlaceHolderID="cphMainBody" runat="server"> |
| <script type="text/javascript"> |
| function KeyPressed(sender, eventArgs) |
| { |
| //alert(eventArgs.get_keyCode()); |
| if (eventArgs.get_keyCode()==13) |
| { |
| //alert('Cancel me'); |
| //selectedRow = -1; |
| eventArgs.set_cancel(true); |
| //FireCommandEvent ("Update", GridCommandEventArgs); |
| //return false; |
| } |
| } |
| </script> |
| <asp:ObjectDataSource ID="ObjectDataSourceLookup" runat="server" |
| DeleteMethod="Delete" InsertMethod="Insert" |
| SelectMethod="GetDT" UpdateMethod="Update" |
| TypeName="MIDI_Internal.BLL_Noun" > |
| <DeleteParameters> |
| <asp:Parameter Name="NounID" Type="Int32" /> |
| </DeleteParameters> |
| <UpdateParameters> |
| <asp:Parameter Name="NounID" Type="Int32" /> |
| <asp:Parameter Name="Noun" Type="String" /> |
| </UpdateParameters> |
| <SelectParameters> |
| <asp:Parameter Name="NounID" Type="Int32" /> |
| </SelectParameters> |
| <InsertParameters> |
| <asp:Parameter Name="Noun" Type="String" /> |
| </InsertParameters> |
| </asp:ObjectDataSource> |
| <telerik:RadGrid ID="RadGridLookup" runat="server" AllowFilteringByColumn="True" |
| AllowPaging="True" AllowSorting="True" GridLines="None" Skin="Mac" |
| EnableAJAX="True" width="60%" AllowAutomaticDeletes="true" |
| AllowAutomaticInserts="true" AllowAutomaticUpdates="true" |
| PagerStyle-Mode="NextPrevNumericAndAdvanced" ClientSettings-Resizing-AllowColumnResize="true" |
| DataSourceID="ObjectDataSourceLookup" |
| OnItemDeleted="RadGridLookup_ItemDeleted" OnItemDataBound="RadGridLookup_ItemDataBound" |
| OnDeleteCommand="RadGridLookup_DeleteCommand" OnItemInserted="RadGridLookup_ItemInserted" |
| OnInit="RadGridLookup_Init" OnColumnCreated="RadGridLookup_ColumnCreated" |
| OnInsertCommand="RadGridLookup_InsertCommand" |
| OnItemUpdated="RadGridLookup_ItemUpdated" |
| OnUpdateCommand="RadGridLookup_UpdateCommand" |
| onitemcommand="RadGridLookup_ItemCommand" |
| onitemcreated="RadGridLookup_ItemCreated" > |
| <ClientSettings AllowKeyboardNavigation="true" ClientEvents-OnKeyPress="KeyPressed"> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" Position="Bottom"></PagerStyle> |
| <MasterTableView allowmulticolumnsorting="True" pagesize="15" CommandItemDisplay="TopAndBottom" |
| autogeneratecolumns="False" DataKeyNames="NounID" datasourceid="ObjectDataSourceLookup" > |
| <RowIndicatorColumn Visible="False"> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn Visible="False" Resizable="False"> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="~\RadControls\Skins\Mac\Grid\Update.gif" |
| EditImageUrl="~\RadControls\Skins\Mac\Grid\Edit.gif" InsertImageUrl="~\RadControls\Skins\Mac\Grid\AddRecord.gif" |
| CancelImageUrl="~\RadControls\Skins\Mac\Grid\Cancel.gif" |
| UniqueName="EditCommandColumn" EditText="Edit Noun"> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn DataField="NounId" DataType="System.Int32" HeaderText="ID" |
| ReadOnly="True" SortExpression="NounId" UniqueName="NounId" Visible="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn HeaderText="Noun" DataField="Noun" SortExpression="Noun" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" UniqueName="NounTemplate"> |
| <ItemTemplate > |
| <asp:Label ID="lblNoun" runat="server" Text='<%#Eval("Noun")%>' /> |
| </ItemTemplate> |
| <EditItemTemplate > |
| <asp:TextBox ID="txtNoun" Text='<%#Bind("Noun")%>' runat="server" Width="80%" /><asp:RequiredFieldValidator ID="rValNoun" runat="server" ControlToValidate="txtNoun" ErrorMessage="*" Enabled="true" Text="Required Field" /> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this record?" ButtonType="ImageButton" ImageUrl="~\RadControls\Skins\Mac\Grid\Delete.gif" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"> |
| <HeaderStyle Width="20px" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| </asp:Content> |
| using System; |
| using System.Collections; |
| using System.Configuration; |
| using System.Data; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Web.UI.HtmlControls; |
| using System.Collections.Generic; |
| using Telerik.Web.UI; |
| namespace MIDI_Internal.Lookups.NSNs |
| { |
| public partial class Nouns : MIDI_Internal.AppCode._libraries.LookupBasePage |
| { |
| protected void Page_PreInit(object sender, EventArgs e) |
| { |
| Page.Theme = (string)Session["MyTheme"]; |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| RadGridLookup.MasterTableView.EditMode = GridEditMode.InPlace; |
| // wire sort event handler to take care of sorting after an insert occurs (see base class event handler) |
| RadGridLookup.SortCommand += new GridSortCommandEventHandler(RadGridLookup_SortCommand); |
| } |
| /// <summary> |
| /// handles users selection to change the paging style at the footer of the grid |
| /// </summary> |
| /// <param name="sender"></param> |
| /// <param name="e"></param> |
| protected virtual void ddlPaging_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| // Get current selected Paging Option // |
| //string currentPager = ddlPaging.SelectedValue.ToString(); |
| //UpdatePagingThemes(RadGridLookup, currentPager); |
| } |
| /// <summary> |
| /// When a noun is inserted in the grid, ascertain there are no duplicate nouns in the tbMIDI_noun table that exist with this noun, |
| /// this event will look for this Noun and cancel the insert if a duplicate exist, display to user. |
| /// Requirements met: |
| /// 4.5.3.1.4 NOUN-1 Noun - no duplicates |
| /// 4.5.3.1.2 NOUN-2 Ability to add a new noun |
| /// </summary> |
| /// <param name="source">RadGrid</param> |
| /// <param name="e"></param> |
| protected void RadGridLookup_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| if ((e.Item is GridDataInsertItem) && (e.Item.OwnerTableView.IsItemInserted)) |
| { |
| GridDataInsertItem edititem = (GridDataInsertItem)e.Item; |
| string strVal = ((TextBox)edititem["NounTemplate"].FindControl("txtNoun")).Text; |
| AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable _noun = new MIDI_Internal.AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable(); |
| _noun = BLL_Noun.GetDT(null); |
| DataRow[] _dr1 = _noun.Select("Noun='" + strVal.Replace("'", "''").ToString() + "'"); |
| if (_dr1.Length > 0) |
| { |
| e.Canceled = true; |
| DisplayAlertMessage("Can not insert this noun, the noun already exists"); |
| } |
| _noun.Dispose(); |
| _noun = null; |
| } |
| } |
| /// <summary> |
| /// When an item is deleted from the noun grid, ascertain there are no NSNs that exist with this noun, user must delete these first. |
| /// this event will look for thise NSNs and cancel the delete if NSNs exist, display to user. |
| /// Requirements met: |
| /// 4.5.3.1.4 NOUN-4 |
| /// 4.5.3.1.4 NOUN-4.1 |
| /// </summary> |
| /// <param name="source">RadGrid</param> |
| /// <param name="e"></param> |
| protected override void RadGridLookup_DeleteCommand(object source, GridCommandEventArgs e) |
| { |
| base.RadGridLookup_DeleteCommand(source, e); |
| int id = 0; |
| AppCode.DALs.MIDI_DAL.tbMIDI_NSNDataTable _nsn = new MIDI_Internal.AppCode.DALs.MIDI_DAL.tbMIDI_NSNDataTable(); |
| //data key value not in the GridCommandEventArgs object, need to extract |
| //id = int.Parse(((GridTableCell)(RadGridLookup.MasterTableView.Controls[0] as Table).Rows[e.Item.RowIndex].Cells[3]).Text); |
| id = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["NounID"].ToString()); |
| //_nsn = BLL_NSN.GetDT(null); |
| _nsn = BLL_NSN.RetrieveNSNByNounForm(-1, id); |
| DataRow[] _dr1 = _nsn.Select("nounId=" + id.ToString()); |
| if (_dr1.Length > 0) |
| { |
| e.Canceled = true; |
| string NSNs = ""; |
| for (int i = 0; i < _dr1.Length; i++) |
| { |
| NSNs += @"\n"; |
| NSNs += "" + _dr1[i]["NSN"].ToString() + ""; |
| } |
| DisplayAlertMessage("Can not delete this noun, NSN records exist: " + NSNs); |
| } |
| _nsn.Dispose(); |
| _nsn = null; |
| } |
| /// <summary> |
| /// When a noun is updated in the grid, ascertain there are no nouns that match the updated value in the tbMIDI_Noun table, |
| /// can not add duplicates |
| /// this event will look for this noun in tbMIDI_Noun and cancel the update if it exist, display to user. |
| /// Requirements met: |
| /// 4.5.3.1.4 NOUN-3 Ability to select and modify an existing noun |
| /// </summary> |
| /// <param name="source">RadGrid</param> |
| /// <param name="e"></param> |
| protected override void RadGridLookup_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| //Get the GridEditableItem of the RadGrid |
| GridEditableItem eeditedItem = e.Item as GridEditableItem; |
| //Get the primary key value using the DataKeyValue. |
| string NounID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["NounID"].ToString(); |
| //Access the textbox from the edit form template and store the values in string variables. |
| string strVal = (editedItem["NounTemplate"].FindControl("txtNoun") as TextBox).Text; |
| AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable _noun = new MIDI_Internal.AppCode.DALs.MIDI_DAL.tbMIDI_NounDataTable(); |
| _noun = BLL_Noun.GetDT(null); |
| DataRow[] _dr1 = _noun.Select("Noun='" + strVal.Replace("'", "''").ToString() + "'"); |
| if (_dr1.Length > 0 && (string.Compare(strVal, (string)Session["savedOldValue"], StringComparison.CurrentCultureIgnoreCase) != 0)) |
| { |
| e.Canceled = true; |
| DisplayAlertMessage("Can not update this noun, the noun name already exists in the database."); |
| (editedItem["NounTemplate"].FindControl("txtNoun") as TextBox).Text = (string)Session["savedOldValue"]; |
| } |
| _noun.Dispose(); |
| _noun = null; |
| } |
| protected override void RadGridLookup_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| base.RadGridLookup_ItemCreated(sender, e); |
| if (e.Item is GridFilteringItem) |
| { |
| AdjustFilterColumnTextBox("NounTemplate", 80, e); |
| } |
| } |
| } |
| } |
| <telerik:RadContextMenu ID="contextColumns" runat="server" Flow="Vertical" Skin="Hay" OnClientItemClicked="OnMenuClick"> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| <Items> |
| <telerik:RadMenuItem runat="server" Text="Show Columns" Value="Columns"> |
| <Items> |
| <telerik:RadMenuItem runat="server" Text="Id" State="checked" /> |
| <telerik:RadMenuItem runat="server" Text="First Name" State="checked" /> |
| <telerik:RadMenuItem runat="server" Text="Last Name" State="checked" /> |
| <telerik:RadMenuItem runat="server" IsSeparator="true" /> |
| <telerik:RadMenuItem runat="server" Text="Apply" Value="menuApply" /> |
| </Items> |
| </telerik:RadMenuItem> |
| </telerik:RadMenuItem> |
| </Items> |
| </telerik:RadContextMenu> |
| function OnMenuClicked(sender, args) { |
| var item = args.get_item(); |
| switch(item.get_value()) { |
| case "menuApply" : |
| // Here I need to apply changes and that's all |
| break; |
| default : |
| ToggleCheckImage(item); |
| this_function_does_not_exists(); // the only way to keep the menu open |
| } |
| } |
Hi
I have built a dynamic grid on the Page Init
Now I need to hook up the client side events (OnRowDblClick etc…) for this type of grid. Is this possible??
P