Reputation: 145
I have a gridview and i want to pass rowindex value to javascript. I tried with following code but its not working.
In Gridview
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" onclick="javascript:return checkSts('<%# DataBinder.Eval(Container.DataItemIndex) %>')" />
</ItemTemplate>
</asp:TemplateField>
In Javascript:
function checkSts(i) { alert(i); }
Upvotes: 1
Views: 5228
Reputation: 1
You can get rowindex
of element by using parentElement
to reach to the row in which particular elemnt is nested
eg.
onclick="callme(this)"
function callme(obj)
{
obj.parentElement.parentElement.rowIndex--- this wud be rowindex of the row.
}
Upvotes: 0
Reputation: 66641
You can type it as
<input type="checkbox" onclick="return checkSts('<%#Eval("FieldName")%>')" />
and work.
Alternative with asp:checkbox
<asp:CheckBox runat="server" ID="chBEna" onclick='<%#getCode(Container.DataItem)%>' />
and on code behind
protected string getCode(object oItem)
{
string cPid = DataBinder.Eval(oItem, "FieldName").ToString();
return "return checkSts('" + cPid + "')";
}
both checked and works.
Upvotes: 1