How can I get an ASP.Net grid element using Javascript

I use Grid View in asp.net, I want Element to click on the grid, how can I do this? The grid has column id, name, warp, weft, etc., I want to select the selected cell data using Javascript, let me know.

Please, help...

Atif Relations

+3
source share
2 answers

To track which button is pressed, you must set row Indexas a parameter for the JS function, for example ...

 protected void grdForecast_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType ==DataControlRowType.DataRow )
    {
        ((Button)e.Row.FindControl("buttonId")).Attributes.Add("onclick", "javascript:update(" + (e.Row.RowIndex ) + ");");
    }
}

And then in JavaScript:

<script language="javascript" type="text/javascript">
    function update(ri) {
        var grd = document.getElementById('<%= GridView1.ClientID %>');
        SecondCellValue = grd.rows[ri].cells[1].childNodes[0].value
        ThirdCellValue = grd.rows[ri].cells[2].childNodes[0].value
    }
</script>
0
source

, ? , . PreRender ScriptManager. id .

jquery ...

$('#myTable td').click(function () {
  alert($(this).html());
});
0

All Articles