Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
Actually i want to show contextmenu on right click of datagrid cell. my contextmenu is showing but i want to get rowindex of row which is clicked by user.i have a hidden field bind in datagrid.i want to get value of hiddenfield of selected rowindex.

C#
$(document).ready(function () {
            try {
                $("#myMenu").hide();
                $("table[id$='Grd_Stock'] > tbody > tr").bind("contextmenu", function (e) {
                    $("#myMenu").hide();
                    e.preventDefault();

//it shows text of first cell of selected row
                    rowid = $(this).children(':first-child').text();


//it shows undefined
C#
var hv = $('#hd_lead_code').attr("value");
                    alert(hv);



});



hd_lead_code is id of my hidden field
#myMenu is my context menu like this:

C#
<div id="myMenu1" class="contextMenu">
                            <table style="width:100%;">
                            <tr><td önclick="fnView();">View Product</td></tr>
                            <tr><td önclick="fnDelete();">Delete Product</td></tr>
                            <tr><td>Team Members</td></tr>
                            <tr><td><asp:DropDownList ID="ddlmembers" runat="server" Width="110px"></td></tr>
                            <tr><td><asp:Button ID="btnassign" runat="server" Width="100px" Text="Assign" 
                                    onclick="btnassign_Click" /></td></tr>
                            </table>
                        </div>




Html code of hidden field:

XML
<asp:TemplateField HeaderText="Cust Name" SortExpression="lead_name">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lbtn_name" Width="200px" CssClass="grdlinkbtn" runat="server"
                                                    OnClick="lbtn_name_click" Text='<%#Eval("lead_name") %>' CausesValidation="false" ></asp:LinkButton>
                                                <asp:HiddenField ID="hd_lead_code" Value='<%#Eval("lead_code") %>' runat="server" />
                                            </ItemTemplate>
                                            <ItemStyle Width="200px" />
                                            <HeaderStyle Font-Bold="true" />
                                        </asp:TemplateField>
Posted
Updated 7-Nov-13 2:08am
v3
Comments
Sampath Lokuge 7-Nov-13 5:09am    
Can you put the Grid code with hidden field ?
Member 8233601 7-Nov-13 5:27am    
please help me out i am in big trouble

1 solution

You didn't show the grid code above.But I hope you're having a problem where the way you access the hidden field.

You can access your hidden field is as below (this is a sample):

Declare Hidden Field - HTML

<input name="hiddenField" type="hidden" value="5" id="idHidden"/>



Access it from JS

var hiddenFieldValue = $("#idHidden").val();


Out put = 5

Note : Change above according to you situation.
 
Share this answer
 
v3
Comments
Member 8233601 7-Nov-13 7:45am    
already tried this but wont work.please tell how could i get rowindex on right click of any cell of datagrid
Sampath Lokuge 7-Nov-13 7:46am    
What it says ?
Member 8233601 7-Nov-13 7:47am    
undefined object
Sampath Lokuge 7-Nov-13 7:55am    
Can you put your grid view's html code with hidden field (put it on your post.Not here)?
Sampath Lokuge 7-Nov-13 8:14am    
Check the value of the hidden field by using chrome or fire bug dev Tool ? And also check the value of hidden field's 'Id' (B'cos the way u declared there're having many items with same id)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900