I have a gridview .When i click on one row in it i have to go to javascript which is like this.
<script type="text/javascript" language="javascript">
function GetDetails(rowNo)
{
document.getElementById('hidRowNo').value = rowNo
document.getElementById('btnDet').click();
}
</script>
I have written following code in codebehind
protected void btnDet_Click(object sender, EventArgs e)
{
if (hidRowNo.Value != "")
{
int rowNo = Convert.ToInt32(hidRowNo.Value);
TextBox1.Text = GridView1.Rows[rowNo].Cells[0].Text;
TextBox2.Text = GridView1.Rows[rowNo].Cells[1].Text;
TextBox3.Text = GridView1.Rows[rowNo].Cells[2].Text;
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "GetDetails(" + e.Row.RowIndex + ");");
}
}
The problem is javascript is working but document.getElementById(‘btnDet’).click(); is not working.While debugging also,control is not moving to btnDet_Click.what change i have to include to move control to btnDel_Click in code behind.
can anybody help?
What about
instead of
In the server side page load event just add this code…
Check this msdn article here
But your code also should work.
Have you tried clicking on the button directly. Does this work?