Monday 12 November 2012

finding the values inside the nested gridview Using Javascript / (using rowindex to find the nested gridview)/ (finding the selected rowindex of gridview on mouse click on the gridview row)



In Design Page

<script language="javascript" type ="text/javascript" >

//get the row index and client id ,cell value
function showClickPage(rowid,id,selectedid)
{
 
var billamt=0;
var admissibleamt=0;
var nonadmissibleamt=0;
var billamt_tot=0;
var admissibleamt_tot=0;
var nonadmissibleamt_tot=0;
 var gridView1 = document.getElementById('<%=GVBillDetails.ClientID %>');
 var idExt=rowid ;
     if(parseInt(idExt,10) <= 9)
     {
         idExt = "0" + idExt ;               
     }           
     var VExtGrid = "GVBillDetails_ctl"+idExt;       
     var gridView = document.getElementById(VExtGrid+"_GVBillDetails1");
     for (var i = 1; i < gridView.rows.length - 1; i++)
     {
        var inputs1 = gridView.rows[i].getElementsByTagName('input')[0];
          if (inputs1.value.length<1)
          {
           nonadmissibleamt=0;
          }
         else
          {
           nonadmissibleamt =parseFloat(inputs1.value);
          }
       nonadmissibleamt_tot = nonadmissibleamt_tot +   nonadmissibleamt;
     }
      gridView.rows[gridView.rows.length - 1].getElementsByTagName('input')[0].value = nonadmissibleamt_tot;
      for (var i = 1; i < gridView.rows.length - 1; i++)
     {
        var inputs2 = gridView.rows[i].getElementsByTagName('input')[1];
          
          if (inputs1.value.length<1)
          {
           admissibleamt=0;
          }
         else
          {
           admissibleamt =parseFloat(inputs2.value);
          }
       admissibleamt_tot = admissibleamt_tot +   admissibleamt;
     }
      gridView.rows[gridView.rows.length - 1].getElementsByTagName('input')[1].value = admissibleamt_tot;  
}
</script>


in code behind:


 protected void GvBilldeatails_OnRowCreated(object sender, GridViewRowEventArgs e)
    {
       /// Gridview index will starts with  -1 so we are adding 2 to the current index here
       /// call the javscript function with 3 parameters as we are passing here



        int index = e.Row.RowIndex + 2;

        e.Row.Attributes.Add("onclick", "showClickPage('" + index + "','" + e.Row.ClientID + "','" + e.Row.Cells[0].Text + "');");

    }

-------------------------


or another method


You can attach an mouse over event handler to the rows of the grid in the OnRowDataBound event handler:

C#:
protected void OnGridRowDataBound(object sender, GridRowEventArgs args)
{
        args.Row.Attributes["onmouseover"] = "handleMouseOver(" + args.Row.RowIndex.ToString() + ")";
        ...
}

JavaScript:
<script type="text/javascript">
        function handleMouseOver(rowIndex) {
                alert('mouse over: ' + rowIndex);
        }

///after finding rowindex here same as above javscript we need to fallow

</script>