<script language="JavaScript">
/**
*根据传入的id显示右键菜单
*/
function showMenu(id)
{
menuForm.id.value = id;
if("" == id)
{
popMenu(itemMenu,80,"80");
}
else
{
popMenu(itemMenu,80,"111");
}
event.returnValue=false;
event.cancelBubble=true;
return false;
}
/**
*显示弹出菜单
*menuDiv:右键菜单的内容
*width:行显示的宽度
*rowControlString:行控制字符串,0表示不显示,1表示显示,如“101”,则表示第1、3行显示,第2行不显示
*/
function popMenu(menuDiv,width,rowControlString)
{
//创建弹出菜单
var pop=window.createPopup();
//设置弹出菜单的内容
pop.document.body.innerHTML=menuDiv.innerHTML;
var rowObjs=pop.document.body.all[0].rows;
//获得弹出菜单的行数
var rowCount=rowObjs.length;
//循环设置每行的属性
for(var i=0;i<rowObjs.length;i++)
{
//如果设置该行不显示,则行数减一
var hide=rowControlString.charAt(i)!='1';
if(hide)
{
rowCount--;
}
//设置是否显示该行
rowObjs[i].style.display=(hide)?"none":"";
//设置鼠标滑入该行时的效果
rowObjs[i].cells[0].οnmοuseοver=function()
{
this.style.background="#818181";
this.style.color="white";
}
//设置鼠标滑出该行时的效果
rowObjs[i].cells[0].οnmοuseοut=function()
{
this.style.background="#cccccc";
this.style.color="black";
}
}
//屏蔽菜单的菜单
pop.document.οncοntextmenu=function()
{
return false;
}
//选择右键菜单的一项后,菜单隐藏
pop.document.οnclick=function()
{
pop.hide();
}
//显示菜单
pop.show(event.clientX-1,event.clientY,width,rowCount*25,document.body);
return true;
}
function create()
{
window.open("A_1_1.aspx?Action=create&nDepID="+menuForm.id.value+"","","width=200,height=100,toolbar=no , menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}
function update()
{
window.open("A_1_1.aspx?Action=update&nDepID="+menuForm.id.value+"","","width=200,height=100,toolbar=no , menubar=no, scrollbars=no, resizable=no, location=no, status=no");
//alert("update" + menuForm.id.value + "!");
}
function del()
{
window.open("A_1_1.aspx?Action=delete&nDepID="+menuForm.id.value+"","","width=200,height=100,toolbar=no , menubar=no, scrollbars=no, resizable=no, location=no, status=no");
//alert("delete" + menuForm.id.value + "!");
}
function clickMenu()
{
alert("请您点击鼠标右键!");
}
</script>
<!-- 这里用来定义需要显示的右键菜单 -->
<div id="itemMenu" style="display:none">
<table border="0" width="100%" height="100%" bgcolor="#cccccc" style="border:thin" cellspacing="0">
<tr>
<td style="cursor:default;border:outset 1;" align="center" οnclick="parent.create()">新增部门
</td>
</tr>
<tr>
<td style="cursor:default;border:outset 1;" align="center" οnclick="parent.update();">修改部门
</td>
</tr>
<tr>
<td style="cursor:default;border:outset 1;" align="center" οnclick="if(confirm('您真的要删除吗?')) parent.del();">删除部门
</td>
</tr>
</table>
</div>
<!-- 右键菜单结束-->
GridView在.cs中绑定即可。
<asp:GridView BorderColor="Black" ID="GridView1" runat="server" AllowPaging=True DataKeyNames="nDep_ID" PageSize=15 AutoGenerateColumns=False OnPageIndexChanging="GridView1_PageIndexChanging" RowHeaderColumn="ID" BorderStyle="None">
<Columns>
<asp:TemplateField>
<HeaderStyle ForeColor="Black" HorizontalAlign=Left Width=40px />
<ItemStyle Width=40px />
<HeaderTemplate>
<asp:Label ID="he" runat="server">编号</asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="ld" runat="server"><%=id++ %></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sDep_Number" HeaderText="部门编号" >
<HeaderStyle ForeColor="Black" HorizontalAlign=Left Width=60px />
<ControlStyle Width="200px" />
</asp:BoundField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign=Left Width=200px ForeColor="Black"/>
<HeaderTemplate>
<asp:Label ID="name" runat="server">部门名称</asp:Label>
</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="deta" runat="server"><a href="javascript:clickMenu()" oncontextmenu = "showMenu('<%#Eval("nDep_ID") %>')"><%#Eval("sName") %></a></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>