In GridView, when click on checkbox add values from label to TextBox using JavaScript in the same row of Grid

Unni K S

I have 3 columns in a GridView. The first column has CheckBox, Second column has outstanding amount due in Label and Third column contains TextBox to pay Amount.

My problem is that TextBox should be filled with second column value when the checkbox is checked and textbox values should be cleared when checkbox uncheck.

Please refer java script code I have used.

<script type="text/javascript">
          function SelectChange(ChkId, txt1, total) {
              var chk = document.getElementById(ChkId);
              UpdateField(ChkId, txt1, total)

          }

          function UpdateField(ChkId, txt1, total) {
              if (document.getElementById(ChkId).checked == true)
              {
                  var lblvalue = document.getElementById(total).value;
                  document.getElementById(txt1).innerHTML = lblvalue;
              }
              else
              {
                  document.getElementById(txt1).innerHTML = "0";
              }
          }

    </script>

In code behind...

protected void grdFeesCollection_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox txtPayment = (TextBox)e.Row.FindControl("txtPayment");
            Label lblDue = (Label)e.Row.FindControl("lblDue");
            CheckBox chckSelecthead = (CheckBox)e.Row.FindControl("chckSelect");

            chckSelecthead.Attributes["onclick"] = "javascript:return SelectChange('" + chckSelecthead.ClientID + "','" + "','" + txtPayment.ClientID + "','" + lblDue.ClientID + "')";

            txtPayment.Attributes["onKeyup"] = "javascript:return UpdateField('" + chckSelecthead.ClientID + "','" + txtPayment.ClientID + "','" + lblDue.ClientID + "')";

        }
    }

This is not returning any values to TextBox, That is the issue.

fnostro

Code Behind:

protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e ) {
    if ( e.Row.RowType == DataControlRowType.DataRow ) {
        Label    lblDue     =    (Label) e.Row.FindControl("lblDue");
        TextBox  txtPayment =  (TextBox) e.Row.FindControl("txtPayment");
        CheckBox chckSelect = (CheckBox) e.Row.FindControl("chckSelect");

        string js = string.Format( "javascript: return SelectChange( '{0}', '{1}', '{2}' ); ", 
                                    chckSelect.ClientID, 
                                    lblDue.ClientID,
                                    txtPayment.ClientID );

        chckSelect.Attributes[ "onclick" ] = js;
    }
}

JavaScript:

function SelectChange(ChkID, DueID, PaymentID) {

    var CheckBox = document.getElementById(ChkID);
    var Due = document.getElementById(DueID);
    var Payment = document.getElementById(PaymentID);

    Payment.value = (CheckBox.checked ? Due.textContent : "");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to validate textbox in gridview when checkbox is checked in same row of gridview using javascript asp.net

From Dev

Add data from Textbox to GridView on button click

From Dev

Add values from checkbox and radio to a label using JS or Jquery

From Dev

Get gridview row values when checkbox checked

From Dev

GridView - Change footer from control in Grid Data Row using javascript

From Dev

Add Textbox and Label From Hyperlink Click

From Dev

Adding values in a checkbox, textbox and select using javascript

From Dev

Using Javascript to Add Values From a Textbox That Came From PHP

From Dev

how to check the checkbox automatically when i click on a row in enhanced grid in dojo using indirect selection

From Dev

how to get row values when checkbox is checked in gridview

From Dev

how to get row values when checkbox is checked in gridview

From Dev

Add Textbox by a click of a button using javascript

From Dev

How to click TextBox (or Label) to toggle checkbox

From Dev

Get the checkbox values by using radiobutton click in javascript

From Dev

Enable textbox on click of checkbox in each table row

From Dev

Disable textbox when checkbox checked in same cell gridview in edit mode on client side

From Dev

How to get the label value from table row when row number is known, using Javascript

From Dev

How to Get Value from GridView (row click) in javascript

From Dev

Search textbox using checkbox in Javascript

From Dev

Findcontrol for label in gridview using javascript

From Dev

Getting textbox and checkbox values which is in edit item template of gridview in a string

From Dev

How to add row in table with Javascript , table value checkbox,textbox,radio,select option?

From Dev

Add/remove textbox value when checkbox change

From Dev

Add/remove textbox value when checkbox change

From Dev

how to add checkbox column to gridview using sqldataprovider?

From Dev

how to add checkbox column to gridview using sqldataprovider?

From Dev

Hyperlink control in gridview using label values

From Dev

Hyperlink control in gridview using label values

From Dev

How to show other column on label/textbox from DB when click choose on dropdownlist without valuefield or textfield

Related Related

  1. 1

    How to validate textbox in gridview when checkbox is checked in same row of gridview using javascript asp.net

  2. 2

    Add data from Textbox to GridView on button click

  3. 3

    Add values from checkbox and radio to a label using JS or Jquery

  4. 4

    Get gridview row values when checkbox checked

  5. 5

    GridView - Change footer from control in Grid Data Row using javascript

  6. 6

    Add Textbox and Label From Hyperlink Click

  7. 7

    Adding values in a checkbox, textbox and select using javascript

  8. 8

    Using Javascript to Add Values From a Textbox That Came From PHP

  9. 9

    how to check the checkbox automatically when i click on a row in enhanced grid in dojo using indirect selection

  10. 10

    how to get row values when checkbox is checked in gridview

  11. 11

    how to get row values when checkbox is checked in gridview

  12. 12

    Add Textbox by a click of a button using javascript

  13. 13

    How to click TextBox (or Label) to toggle checkbox

  14. 14

    Get the checkbox values by using radiobutton click in javascript

  15. 15

    Enable textbox on click of checkbox in each table row

  16. 16

    Disable textbox when checkbox checked in same cell gridview in edit mode on client side

  17. 17

    How to get the label value from table row when row number is known, using Javascript

  18. 18

    How to Get Value from GridView (row click) in javascript

  19. 19

    Search textbox using checkbox in Javascript

  20. 20

    Findcontrol for label in gridview using javascript

  21. 21

    Getting textbox and checkbox values which is in edit item template of gridview in a string

  22. 22

    How to add row in table with Javascript , table value checkbox,textbox,radio,select option?

  23. 23

    Add/remove textbox value when checkbox change

  24. 24

    Add/remove textbox value when checkbox change

  25. 25

    how to add checkbox column to gridview using sqldataprovider?

  26. 26

    how to add checkbox column to gridview using sqldataprovider?

  27. 27

    Hyperlink control in gridview using label values

  28. 28

    Hyperlink control in gridview using label values

  29. 29

    How to show other column on label/textbox from DB when click choose on dropdownlist without valuefield or textfield

HotTag

Archive