Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a create page and show button that ajax calls Grid page. In Grid page I have a Jquery code to fill Grid selection in textboxes which works fine individually but in create page it doesn't work. Any help here ?

What I have tried:

JavaScript
@*AJAX CODE IN CREATE PAGE*@



    $(document).ready(function() {
        $("#btnShow").click(function () {
            $.ajax({
                url: '@Url.Action("Grid","bankinfoes")',
                type: 'get',
                success: function (vHtml) {
                    $("#dvShow").html("");
                    $("#dvShow").html(vHtml);
                    
                    
                    
                }
            });
            

         });
    });
     
-----------------------------------------------
Grid Page


    $(function() {
            
                $('#webgrid1').find('tr').on('click', function() {
                
                $("#Id").val($(this).children("td:eq(0)").html());
                
                $("#bankname").val($(this).children("td:eq(1)").html());
               
                $("#accountholdername").val($(this).children("td:eq(2)").html());
                
                $("#address").val($(this).children("td:eq(3)").html());
               
                $("#area").val($(this).children("td:eq(4)").html());
                
            });
        });
@{
    ViewBag.Title = "Bind Gridview with Database";
    WebGrid grid = new WebGrid(Model);
}

<h2>Bind GridView in MVC5 with Database</h2>
@grid.GetHtml(tableStyle: "webgrid",
       htmlAttributes: new { id = "webgrid1" },
            headerStyle: "header",
            alternatingRowStyle: "alt",
            columns: grid.Columns

(

    grid.Column("Id", "Id", canSort: true),
    grid.Column("bankname", "bankname", canSort: false),
    grid.Column("accountholdername", "accountholdername", canSort: false),
    grid.Column("address", "address", canSort: false),
    grid.Column("area", "area")


)
)


HTML
<table><tbody><tr>        <td>Bankname</td>        <td></td>    </tr>    <tr>        <td>accountholdername</td>        <td></td>    </tr>    <tr>        <td>address</td>        <td></td>    </tr>    <tr>        <td>area</td>        <td></td>    </tr></tbody></table>
Posted
Updated 2-Nov-17 0:51am
v2
Comments
Karthik_Mahalingam 2-Nov-17 3:48am    
try calling this set of code after binding the data to the gird

$('#webgrid1').find('tr').on('click', function() {

$("#Id").val($(this).children("td:eq(0)").html());

$("#bankname").val($(this).children("td:eq(1)").html());

$("#accountholdername").val($(this).children("td:eq(2)").html());

$("#address").val($(this).children("td:eq(3)").html());

$("#area").val($(this).children("td:eq(4)").html());

});
Vishal 1023 2-Nov-17 4:02am    
It's still Not working
Karthik_Mahalingam 2-Nov-17 4:12am    
do you see any error in chrome console ?
Vishal 1023 2-Nov-17 4:14am    
No Error
Karthik_Mahalingam 2-Nov-17 4:28am    
        // keep an alert in the event and check whether it is hitting on clicking the row
        $('#webgrid1').find('tr').on('click', function() {
            alert('0')

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