GridView鼠标右键

来源:互联网 发布:民营企业并购数据统计 编辑:程序博客网 时间:2024/05/21 10:34

以上是效果截图

aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="QYCarFYApplyManage.aspx.cs"
    Inherits="QYCarFYApplyManage" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>出租车废业审批管理</title>

    <script type="text/javascript">
        function a1(id) {
            if (event.button == "2") {

                $get("HiddenField1").value = id;
            }
            //            switch (event.button) {
            //                case 1: alert('left'); break;
            //                case 2: alert('right'); break;
            //                case 3: alert('left   &&   right'); break;
            //                case 4: alert('middle'); break;
            //                case 5: alert('left   &&   middle'); break;
            //                case 6: alert('right   &&   middle'); break;
            //                case 7: alert('left   &&   middle   &&   right'); break;
            //            }

        }
        function popclose() {
            $find("ModalPopupExtender1").hide();
        }
        function stop() {

            return false;

        }


    </script>

    <style type="text/css">
        .GridViewHead
        {
            background-color: #e0e0e0;
            font-weight: bold;
            font-size: 15px;
        }
        .GridViewRow
        {
            font-size: 14px;
            height: 28px;
        }
    </style>
    <style type="text/css">
        .modalPopup
        {
            background-color: #EDF6FF;
            border-width: 3px;
            border-style: solid;
            border-color: Gray;
            padding: 3px;
        }
        .modalBackground
        {
            background-color: Gray;
            filter: alpha(opacity=70);
            opacity: 0.7;
        }
        .skin0
        {
            position: absolute;
            text-align: left;
            width: 200px;
            border: 2px solid black;
            background-color: menu;
            font-family: Verdana;
            line-height: 20px;
            cursor: default;
            visibility: hidden;
        }
        .skin1
        {
            cursor: default;
            font: menutext;
            position: absolute;
            text-align: left;
            font-family: Arial, Helvetica, sans-serif;
            font-size: 10pt;
            width: 120px;
            background-color: Silver;
            border: 1 solid buttonface;
            visibility: hidden;
            border: 2 outset buttonhighlight;
        }
        .menuitems
        {
            padding-left: 15px;
            padding-right: 10px;
        }
    </style>

    <script type="text/javascript">
<!--        Begin
        var menuskin = "skin1"; // skin0, or skin1
        var display_url = 0; // Show URLs in status bar?
        function showmenuie5() {
            var rightedge = document.body.clientWidth - event.clientX;
            var bottomedge = document.body.clientHeight - event.clientY;
            if (rightedge < ie5menu.offsetWidth)
                ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
            else
                ie5menu.style.left = document.body.scrollLeft + event.clientX;
            if (bottomedge < ie5menu.offsetHeight)
                ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
            else
                ie5menu.style.top = document.body.scrollTop + event.clientY;
            ie5menu.style.visibility = "visible";
            return false;
        }
        function hidemenuie5() {
            ie5menu.style.visibility = "hidden";
        }
        function highlightie5() {
            if (event.srcElement.className == "menuitems") {
                event.srcElement.style.backgroundColor = "highlight";
                event.srcElement.style.color = "white";
                if (display_url)
                    window.status = event.srcElement.url;
            }
        }
        function lowlightie5() {
            if (event.srcElement.className == "menuitems") {
                event.srcElement.style.backgroundColor = "";
                event.srcElement.style.color = "black";
                window.status = "";
            }
        }
        function jumptoie5() {
            if (event.srcElement.className == "menuitems") {
                if (event.srcElement.getAttribute("target") != null)
                    window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
                else
                    window.location = event.srcElement.url;
            }
        }
//  End -->
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="text-align: center">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="700px"
            OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
            <Columns>
                <asp:TemplateField HeaderText="序号"></asp:TemplateField>
                <asp:TemplateField HeaderText="公司名称">
                    <ItemTemplate>
                        <%#Eval("公司名称")%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="车牌号">
                    <ItemTemplate>
                        <%#Eval("车牌号")%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="申请日期">
                    <ItemTemplate>
                        <%#Eval("申请日期")%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="申请人">
                    <ItemTemplate>
                        <%#Eval("申请人")%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="操作">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkbtn_look" runat="server" CommandName="look" CommandArgument='<%#Eval("编号") %>'>查看</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <HeaderStyle CssClass="GridViewHead" Height="30px" HorizontalAlign="Center" />
            <RowStyle CssClass="GridViewRow" />
        </asp:GridView>
    </div>
    <asp:Button ID="Button6" runat="server" Text="Button" Width="0" Height="0" Style="display: none;" />
    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="PanelM"
        DropShadow="true" Drag="true" Y="150" DynamicServicePath="" BackgroundCssClass="modalBackground"
        Enabled="True" TargetControlID="Button6">
    </cc1:ModalPopupExtender>
    <asp:Panel ID="PanelM" runat="server" Style="border: solid 6px #ddd; width:300px;">
        <asp:Panel ID="PanelBody" runat="server" CssClass="modalPopup"
            Style="border: solid 1px #999; font-size: 12px;" ScrollBars="Auto" BorderStyle="Solid"
            BorderWidth="1px">
            <div id="tit" style="border-bottom:solid 1px #999;background-color:#cccccc; padding:6px; font-weight:bold;">
                查看用户的详细信息
            </div>
            <div id="bod" style="background-color:#ffffff; padding:20px;">
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </div>
            <div id="bot" style="border-top:solid 1px #999;background-color:#cccccc; text-align:right;">
                <input type='button' value='关闭' onclick='popclose()' />
            </div>
        </asp:Panel>
    </asp:Panel>
    <div id="ie5menu" class="skin0">
        <asp:LinkButton ID="LinkButton1" runat="server">添加</asp:LinkButton><br />
        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="edits" OnCommand="LinkButton2_Command">修改</asp:LinkButton><br />
        <asp:LinkButton ID="LinkButton3" runat="server" OnClientClick="return confirm('确定要删除吗')">删除</asp:LinkButton>
    </div>
    <asp:HiddenField ID="HiddenField1" runat="server" />

    <script type="text/javascript">
        if (document.all && window.print) {
            ie5menu.className = menuskin;
            document.oncontextmenu = stop;
            document.body.onclick = hidemenuie5;
        }
    </script>

    </form>
</body>
</html>
 

cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RentBLL;

public partial class QYCarFYApplyManage : System.Web.UI.Page
{
    QYCarBFApplyBLL bll = new QYCarBFApplyBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitGridview();
        }
    }
    private void InitGridview()
    {
        GridView1.DataSource = bll.GetList("").Tables[0];
        GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string id = e.CommandArgument.ToString();
        if (e.CommandName == "look")
        {
            Response.Redirect("QYCarFYApplyInfo.aspx?id="+id+"");
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
            e.Row.Attributes.Add("onmousedown", "a1("+e.Row.Cells[0].Text+")");
            e.Row.Attributes.Add("oncontextmenu", "showmenuie5()");
        }
    }

    protected void LinkButton2_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "edits")
        {
            string id = HiddenField1.Value;
            Label1.Text = id;
            ModalPopupExtender1.Show();
        }
    }
}

 

原创粉丝点击