下面是我用来显示的代码
RadContextMenu
右键单击时
RadGrid
排:
HTML格式:
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock3">
<script type="text/javascript" src="~/JavaScript/ClientEventScript.js"></script>
<script type="text/javascript">
; (function ($, undefined) {
var menu;
var grid;
var demo = window.demo = {};
window.onload = function () {
grid = $telerik.findControl(document, "rgInvoice");
menu = $telerik.findControl(document, "RadMenu1");
}
demo.ShowColumnHeaderMenu = function (event, columnName) {
var columns = grid.get_masterTableView().get_columns();
for (var i = 0; i < columns.length; i++) {
if (columns[i].get_uniqueName() == columnName) {
columns[i].showHeaderMenu(event, 75, 20);
}
}
};
demo.RowContextMenu = function (sender, eventArgs) {
var evt = eventArgs.get_domEvent();
if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {
return;
}
var index = eventArgs.get_itemIndexHierarchical();
document.getElementById("radGridClickedRowIndex").value = index;
sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
menu.show(evt);
evt.cancelBubble = true;
evt.returnValue = false;
if (evt.stopPropagation) {
evt.stopPropagation();
evt.preventDefault();
}
};
})($telerik.$);
</script>
</telerik:RadCodeBlock>
<div id="divGrid" runat="server" visible="false">
<%--<asp:Panel ID="Panel1" runat="server" Visible="false">--%>
<telerik:RadGrid ID="rgInvoice" runat="server" AllowSorting="True" AutoGenerateColumns="false"
EmptyDataText="No record available." OnNeedDataSource="rgInvoice_NeedDataSource" Visible="true"
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
EnableEmbeddedSkins="False" ImagesPath="~/App_Themes/MetroRed/Grid" Skin="MetroRed" GridLines="Both"
EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true">
<mastertableview ShowHeadersWhenNoRecords="true" autogeneratecolumns="false" InsertItemDisplay="Top"
InsertItemPageIndexAction="ShowItemOnCurrentPage" ShowFooter="True" CommandItemDisplay="Top" EnableColumnsViewState="false">
<CommandItemSettings ShowAddNewRecordButton="false" />
<Columns>
<telerik:GridBoundColumn HeaderText="SP Id" DataField="SPfoID" SortExpression="SPfoID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Direct Cost" DataField="DCIDescription" SortExpression="DCIDescription">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Business Unit" DataField="BUName" SortExpression="BUName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Status" DataField="Status" SortExpression="Status">
</telerik:GridBoundColumn>
</Columns>
<GroupByExpressions>
<telerik:GridGroupByExpression>
<GroupByFields>
<telerik:GridGroupByField FieldName="BusinessUnit" SortOrder="Ascending" />
</GroupByFields>
<SelectFields>
<telerik:GridGroupByField FieldName="BusinessUnit" HeaderText="Business Unit" />
</SelectFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowContextMenu="demo.RowContextMenu" />
<Selecting AllowRowSelect="true" />
<Scrolling AllowScroll="false"></Scrolling>
</ClientSettings>
</telerik:RadGrid>
<input type="hidden" id="Hidden1" name="radGridClickedRowIndex" />
<telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnItemClick="RadMenu1_ItemClick"
EnableRoundedCorners="true" EnableShadows="true">
<Items>
<telerik:RadMenuItem Text="Add">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Edit">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Delete">
</telerik:RadMenuItem>
</Items>
</telerik:RadContextMenu>
<%--</asp:Panel>--%>
</div>
C编号:
protected void btnInvoice_Click(object sender, EventArgs e)
{
divGrid.Visible = true;
//Panel1.Visible = true;
btnInvoice.Enabled = false;
}
#region Invoice
protected void rgInvoice_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
try
{
_dtInvoice = SDM.Invoice.GetInvoice(_SPID);
rgInvoice.DataSource = _dtInvoice;
}
catch (Exception ex)
{
}
}
#endregion
#region RadMenu
protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)
{
int radGridClickedRowIndex;
radGridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"]);
switch (e.Item.Text)
{
case "Edit":
rgInvoice.Items[radGridClickedRowIndex].Edit = true;
rgInvoice.Rebind();
break;
case "Add":
rgInvoice.MasterTableView.IsItemInserted = true;
rgInvoice.Rebind();
break;
case "Delete":
rgInvoice.MasterTableView.PerformDelete(rgInvoice.Items[radGridClickedRowIndex]);
break;
}
}
#endregion
我通过以下链接进行上述实施:
http://demos.telerik.com/aspnet-ajax/grid/examples/columns-rows/columns/context-menu/defaultcs.aspx
除了我把
雷达网格
在…内
Panel/div
并使其在HTML代码中可见=false,并尝试在按钮单击事件中使其可见=true,
RadContext菜单
不会显示。
RadContext菜单
仅在以下情况下出现
面板/div
可见。
但我必须出示
雷达网格
仅在单击按钮时
RadcontextMenu
.
请让我知道如何在单击按钮时隐藏和显示RadGrid,而不会在数据绑定和显示RadcontextMenu时出现任何问题。
请有人回复。
提前感谢