I have a jquery function which need to be implemented in asp.net grid view. In each row there will be two text boxes, where each row text box has different value according to the user input. The value of second text box depends upon the value of first text
box entered by the user which is calculated using jquery function. And every row will have different user input in the first text box.
the problem with this approach is that whenever I change the value of the first text box in any cell, the value of second text box changes in every row. I think I need to retrieve value of each row, but I do not know how to do this?
Due to nature of Gridview, each control inside is rendered with a generated ID, you did not show how you binding data to gridview, but assuming you binding on code-behind
My suggestion is a small change on your Gridview and use RowDataBound to set onChange event pointing to 2 distinct JS functions
Here is your griview using TextBox control instead of Input, at the end TextBox render as Input.
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
42 Points
184 Posts
manipulating asp grid view text box data using jquery
Jun 12, 2020 08:32 AM|scala_1988|LINK
I have a jquery function which need to be implemented in asp.net grid view. In each row there will be two text boxes, where each row text box has different value according to the user input. The value of second text box depends upon the value of first text box entered by the user which is calculated using jquery function. And every row will have different user input in the first text box.
My jquery ::
the problem with this approach is that whenever I change the value of the first text box in any cell, the value of second text box changes in every row. I think I need to retrieve value of each row, but I do not know how to do this?
Participant
1091 Points
673 Posts
Re: manipulating asp grid view text box data using jquery
Jun 12, 2020 03:58 PM|jzero|LINK
Your changes are based on class not ID.
Due to nature of Gridview, each control inside is rendered with a generated ID, you did not show how you binding data to gridview, but assuming you binding on code-behind
My suggestion is a small change on your Gridview and use RowDataBound to set onChange event pointing to 2 distinct JS functions
Here is your griview using TextBox control instead of Input, at the end TextBox render as Input.
With help of Gridview.rowDatabound event, add "OnChange" attribute to each TextBox and point to Javascript Function
Then on Javascript, make your changes on Textbox using ID
Participant
1253 Points
943 Posts
Re: manipulating asp grid view text box data using jquery
Jun 13, 2020 03:53 AM|yogyogi|LINK
You should use jQuery Siblings method here.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Contributor
2340 Points
736 Posts
Re: manipulating asp grid view text box data using jquery
Jun 15, 2020 03:45 AM|XuDong Peng|LINK
Hi, scala_1988
If a suitable selector is used, it can also be implemented. I think jQuery find maybe can help you.
Please refer to the following simple example:
Result:
Best regards,
Xudong Peng