samedi 14 mai 2016

In GridView, when click on checkbox add values from label to TextBox using JavaScript

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 + "')";

        }
    }




Aucun commentaire:

Enregistrer un commentaire