hello , my programm in asp.net and jquery that allows me to have a simple context menu, i would be worth some help so that when a user right clicks in option comment for example that the line is redirected in other gridview page

david 237 41 Reputation points
2022-11-17T09:42:50.533+00:00

<%@ Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeFile="ListTask.aspx.cs" Inherits="Task_ListTask" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<link href="/assets/css/StyleSheet.css" rel="stylesheet" type="text/css" />  
<link href="/assets/css/confirm.css" rel="stylesheet" type="text/css" />  
<link href="/assets/css/jquery.contextMenu.css" rel="stylesheet" type="text/css" />  
<script src="/assets/js/jquery-1.2.6.min.js" type="text/javascript"></script>  
<script src="/assets/js/jquery.simplemodal-1.1.1.js" type="text/javascript"></script>  
<script src="/assets/js/jquery.contextMenu.js" type="text/javascript"></script>  
<!-- IE 6 hacks -->  
<!--[if lt IE 7]>  

<link type='text/css' href='_assets/css/confirm_ie.css' rel='stylesheet' media='screen' />
<![endif]-->
<style type="text/css">
.customerRow
{
}
.gvhide
{
display: none;
}
</style>
<script language="javascript" type="text/javascript">
var Id_Task = null;
var Description = null;
var Owner = null;
var Date_request = null;
var deadline = null;
var probleme_rencontre = null;
var commentaires = null;
var statut = null;

    $(document).ready(function () {  
        $(".customerRow").contextMenu({ menu: 'myMenu' }, function (action, el, pos) { contextMenuWork(action, el, pos); });  
        $(".openmenu").contextMenu({ menu: 'myMenu', leftButton: true }, function (action, el, pos) { contextMenuWork(action, el.parent("tr"), pos); });  
    });  

    function contextMenuWork(action, el, pos) {  
        var rowindex = (el[0].rowIndex * 1 - 1);  
        Id_Task = $("#Gridview1_Id_Task" + rowindex).html();  
        Description = $("#Gridview1_Description" + rowindex).html();  
        Owner = $("#Gridview1_Owner" + rowindex).html();  
        Date_request = $("#Gridview1_Date_request" + rowindex).html();  
        deadline = $("#Gridview1_deadline" + rowindex).html();  
        probleme_rencontre = $("#Gridview1_probleme_rencontre" + rowindex).html();  
        commentaires = $("#Gridview1_commentaires" + rowindex).html();  
        statut = $("#Gridview1_statut" + rowindex).html();  
        switch (action) {  
            case "delete":  
                {  

                    var msg = "Delete " + ContactName + "?";  
                    confirm(msg);  
                    break;  
                }  
            case "insert":  
                {  
                    alert("Insert");  
                    break;  
                }  

            case "edit":  
                {  
                    alert("Edit");  
                    break;  
                }  
        }  
    }  

    function pageLoad() {  
        $(".customerRow").contextMenu({ menu: 'myMenu' }, function (action, el, pos) { contextMenuWork(action, el, pos); });  
        $(".openmenu").contextMenu({ menu: 'myMenu', leftButton: true }, function (action, el, pos) { contextMenuWork(action, el.parent("tr"), pos); });  
    }  

      
</script>  

 
<asp:ScriptManager ID="ScriptManager1" runat="server">  
</asp:ScriptManager>  
<asp:UpdatePanel ID="UpdatePanel1" runat="server">  
    <ContentTemplate>  
        <br /><br />  
        <div class="d-flex">  
            <asp:Button ID="printButton" runat="server" type="button" class="btn btn-warning text-white" Text="Print" OnClientClick="javascript:window.print();" />  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
        <div class="d-flex">  
            <asp:TextBox ID="txtSearch" runat="server" class="form-control"></asp:TextBox>  
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
            <asp:Button ID="btnSearch" runat="server" Text="Search" class="btn btn-warning text-bg-danger white"  />  
   
         </div>  
        <br />  
  
        </div>  
        <br />    
        <asp:GridView ID="Gridview1" class="mx-auto" runat="server" AutoGenerateColumns="False" OnRowDataBound="Gridview1_RowDataBound"  
            AllowPaging="True"  PageSize="6" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None">  
            <AlternatingRowStyle BackColor="White" />  
            <Columns>  
                 <asp:BoundField DataField="Id_Task" HeaderText="Id_Task" SortExpression="Id_Task" Visible="false" />  
                <asp:BoundField DataField="Taches a faire" HeaderText="Taches a faire" SortExpression="Taches a faire" />  
                <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />  
                <asp:BoundField DataField="date de requete" HeaderText="date de requete" SortExpression="date de requete" />  
                <asp:BoundField DataField="deadline" HeaderText="deadline" SortExpression="deadline" />  
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />  
              <asp:HyperLinkField Text="Details" DataNavigateUrlFields="Id_Task,Taches a faire,Username,date de requete" DataNavigateUrlFormatString="~/Admin/NewPage.aspx?Id_Task={0}&Taches a faire={1}&Username={2}&date de requete={3}" />  

                
            </Columns>  
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />  
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />  
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />  
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />  
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />  
            <SortedAscendingCellStyle BackColor="#FDF5AC" />  
            <SortedAscendingHeaderStyle BackColor="#4D0000" />  
            <SortedDescendingCellStyle BackColor="#FCF6C0" />  
            <SortedDescendingHeaderStyle BackColor="#820000" />  
        </asp:GridView>  
         
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LoginDBConnectionString %>" SelectCommand="SELECT Commentaire.id_Commentaire, Commentaire.update_deadline, Tasks.Id_Task,Tasks.[Taches a faire], Tasks.[date de requete], Tasks.deadline, Users.Username, Statut.Status FROM  Tasks INNER JOIN Users ON Tasks.porteur = Users.UserId LEFT JOIN Commentaire ON Tasks.Id_Task=Commentaire.id_Commentaire LEFT JOIN Statut ON Statut.id_statut=Commentaire.Status" FilterExpression="Username LIKE '{0}%' ">  
            <FilterParameters>  
                <asp:ControlParameter Name="Username" ControlID="txtSearch" PropertyName="Text" />  
            </FilterParameters>  

        </asp:SqlDataSource>  
         
    </ContentTemplate>  
</asp:UpdatePanel>  
<!-- Right Click Menu -->  
<ul id="myMenu" class="contextMenu">  
    <li class="insert"><a href="#insert">Add Comment</a></li>  
    <li class="edit"><a href="#edit">Edit</a></li>  
    <li class="delete"><a href="#delete">Delete</a></li>  
</ul>  

</asp:Content>

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,252 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
866 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    2022-11-18T09:24:02.087+00:00

    Hi @david 237 ,
    First you can open a URL with parameters in a window that calls code via window.location.href. Then use Request.QueryString to get the parameters of the url.

       case "insert":  
                        {  
                            window.location.href = "WebForm1.aspx?CustomerID=" + CustomerID;                                                 
                            break;  
                        }  
    

    262572-image.png
    WebForm1.aspx

    <div>  
                <asp:GridView ID="GridView1" runat="server"></asp:GridView>  
            </div>  
    -----------------------------------  
     protected void Page_Load(object sender, EventArgs e)  
            {  
                string id = Request.QueryString["CustomerID"];  
                string SelectQuery = "Select * from [Test] where Id='" + id + "'";  
                if (!Page.IsPostBack)  
                {  
                    string StrSqlDbConStringTT = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;  
      
                    using (SqlConnection con3 = new SqlConnection(StrSqlDbConStringTT))  
                    {      
                        SqlCommand cmd1 = new SqlCommand(SelectQuery, con3);      
                        DataTable ds11 = new DataTable();  
                        SqlDataAdapter da11 = new SqlDataAdapter(cmd1);  
                        da11.Fill(ds11);  
      
                        GridView1.DataSource = ds11;  
                        GridView1.DataBind();  
      
                    }  
                }  
            }  
    

    262538-12.gif
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.