How to get row index of a gridview row clicked by a user on it by javascript ?
views:
642answers:
3
A:
Here is a little sample:
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="button" value="getIndex" onclick="getIndex(<%# Container.DataItemIndex %>);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
function getIndex(index) {
alert(index);
}
</script>
iburlakov
2010-01-26 11:15:28
A:
I believe the answer to this older question will provide the answer you need.
Jason Berkan
2010-01-26 13:21:03
A:
you can add javascript function on rowdatabound and set parameter row index like...
protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Button)e.Row.FindControl("yourButtonID")).Attributes.Add("onclick", "javascript:JSfunctionName(" + (e.Row.RowIndex) + ");");
}
}
<script language="javascript" type="text/javascript">
function JSFunctionName(ri)
{}
Muhammad Akhtar
2010-01-26 13:40:54