Click here to Skip to main content
15,904,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

am binding Gridview using jquery,in My gridview have 4 columns stockId,Pariculars,Quantity,Rate.stockId visible false,and binded in label inside gridview ,others are textBox
I want to save gridview am using this code but i didn't get data


PHP
$.each($("table[id*=gvstockOut] input[id$=txtstockId]"), function ()
            SaveData = SaveData + ", {'StockId':'" + $(this).val() + "','particular':'" + $(this).closest("tr").find("input[id*=txtParticulars]").val() + "','Quantity':'" + $(this).closest("tr").find("input[id*=txtQuantity]").val() + "','Rate':'" + $(this).closest("tr").find("input[id*=Rate]").val() + "','Value':'" + $(this).closest("tr").find("input[id*=lblTotal]").val() + "'} ";

        });
Posted

1 solution

It would have been better if you would have included the rendered HTML for gridview. Even then please check the following things -

1. Check if you are using the right attribute selectors.
2. Check if you have got the right tr
3. If you are using label in case of Total, please check it should render a span rather than an input.

And, you can write the code like -
C#
var stockData = [];
$("table[id$='gvstockOut'] input[id$='txtstockId']").each(function(){

    var stockItem = {};
    var closestParentTr = $(this).parents('tr')[0];

    stockItem.StockId = $(this).val();
    stockItem.particular = $(closestParentTr).find("input[id*='txtParticulars']").val();
    stockItem.Quantity = $(closestParentTr).find("input[id*='txtQuantity']").val();
    stockItem.Rate = $(closestParentTr).find("input[id*='Rate']").val();
    stockItem.Value= $(closestParentTr).find("input[id*='lblTotal']").val();
    stockData.push(stockItem);

});

var stockJSONData = JSON.stringify(stockData);

Note: I have just rewritten your code for making it easier to debug. So, please check the above mentioned points first.

And, check using any debugger or putting console.log after each value you are getting. So, that will make you clear if you are getting the right value or not.

Thanks
 
Share this answer
 

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