question

david237-9695 avatar image
0 Votes"
david237-9695 asked LanHuang-MSFT commented

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

<%@ 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>

office-js-devdotnet-aspnet-webpages
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @david237-9695,
What problem are you currently facing? Maybe you can use F12 developer tools to see the error message.
Navigating the F12 Developer Tools Interface
Best regards,
Lan Huang


1 Vote 1 ·

hi @LanHuang-MSFT this code launch correctly, so i need help to get data row with contextmenu to link this data row in another gridview page

0 Votes 0 ·

Hi @david237-9695,
Is there any update to this issue? If you have any question, just feel free to let me know.

0 Votes 0 ·

1 Answer

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered LanHuang-MSFT commented

Hi @david237-9695,
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.





image.png (146.1 KiB)
image.png (63.9 KiB)
2.gif (236.1 KiB)
2.txt (2.6 KiB)
image.png (5.9 KiB)
12.gif (79.8 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi @LanHuang-MSFT please it is possible to link directly in other row in other page with contextmenu ?

0 Votes 0 ·

Hi @david237-9695,
I re-edited the answer according to your needs, you can check it out.
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.
Best regards,
Lan Huang

0 Votes 0 ·