views:

137

answers:

1

I need to pass a GridView DataKey (Primary key) as parameter in an ajax call JSON with jquery.

However,i dont't to expose my primary key column in source code HTML.I've already tried to hide the TD (first column) of the table,but it doenst hide in source code.

Here is the Jquery code:

    $(function(){
   $("tr").each(function(){//hide primary key columns in design
        $("td:first",this).hide();
        $("th:first",this).hide();
   });

        $("tr:not(:first)").click(function(){
           $.ajax({
            type:"POST",
            url:"CRUDWeb.asmx/DeleteRow",
            data:"{'duviID': '" + $(this).children("td:first").html() + "'}",//get primary key
            contentType:"application/json; charset=utf-8",
            dataType:"json",
            success:function(){},
            error:function(rh){alert(rh.responseText);}
            });
        });
    });

Any ideas?

+1  A: 

You can't.

The primary key must be printed somewhere in the source code, else the jquery (client side) can't send the information to the ajax call.

The only solution is if there is another unique key you can print in your source code, then you can send this key to your script and lookup the Primary key.

Tim